Tag Info

Hot answers tagged

26

if you need the gmt_offset then <?php echo get_option('gmt_offset'); ?> this will give you an integer like 2 or -2. and if you need the timezone string use <?php echo get_option('timezone_string'); ?> this will give you a string like America/Indianapolis


10

If you can explain it in SQL, you can query for it! There are three places where we want to change the default query: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND wp_postmeta.meta_key = 'startDate' AND ...


10

This is not really an answer, just an attempt to find the specific context for this problem. Please install the following plugin on your site, try to set the three dates and add your result to the second <pre> in the table below. /* Plugin Name: WPSE Sysinfo */ add_action( 'admin_footer', 'wpse_sysinfo' ); function wpse_sysinfo() { $bit = ...


9

You may notice that I did more or less exactly this for Matt's site: http://ma.tt. Every set of posts is grouped by the day. The basic principle is to keep track of your day in the loop, then print the date and related stuff only when it changes. Take a basic Loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_content(); ...


8

I know I'm three months late, but the function you want here is get_date_from_gmt(). The function accepts a GMT/UTC date in Y-m-d H:i:s format as the first parameter, and your desired date format as the second parameter. It'll convert your date to the local timezone as set on the Settings screen. Example usage: echo get_date_from_gmt( date( 'Y-m-d H:i:s', ...


7

Question and expectations While the literal form of this question is practical in context (year 1899) it is a little vague in theoretical sense. How old is old? How far into the past we might want to go? What about the future? Since WordPress had started out as blogging engine, in that contextual sense it evolved to handle following span of time: dates ...


7

They are, very similar but with some nuances: function get_the_date( $d = '' ) { global $post; $the_date = ''; if ( '' == $d ) $the_date .= mysql2date(get_option('date_format'), $post->post_date); else $the_date .= mysql2date($d, $post->post_date); return apply_filters('get_the_date', $the_date, $d); } function ...


7

There is a function in WordPress called current_time(); which you pass either 'timestamp' or 'mysql' to and it returns a time. For more information: http://codex.wordpress.org/Function_Reference/current_time


7

I'm using something like this: date('F, Y', strtotime($data[0]->post_date));


6

Yes, there isn't currently built-in support for CPT archives, but that doesn't mean you can't extend WP to provide it. I just did this myself the other day... This won't create the date-based archives you're looking for, but it will give you virtual archive behavior for custom post types. Adding the date should just be a matter of tweaking the rewrite rules ...


6

Firstly you'll need to stop storing the dates in D d.m format, the queries aren't going to be able to sort based on that data. As wyrfel pointed out, you'll need to use the alternate field option to have two fields, one that shows the pretty(or your chosen) date format, and another that holds the value you store in the DB(in a format that the queries can ...


6

EDIT: Your problem is this: When you save your meta data, you want the date to be saved as a strtotime() date, but you want it to display the date back in the old Y-m-d format. What you need to do is save it as strtotime() and then when displaying the text back in the input, you need to reverse that strtotime()so it can be displayed properly. You can do ...


6

This is quite simple: just replace the get_the_date() or the_date() with echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';


5

You would just need to format the time that is returned by current_time() with the php date() function like this: $my_time = date('G', current_time('timestamp')); The param 'G' tells the function you just want to have the hour part (0 to 23) of the date. Have a look here: http://www.php.net/manual/en/function.date.php


5

echo date('Y-m-d h:i:s', strtotime($cp->post_date)); ... or better use the wordpress functionado echo mysql2date('Y-m-d h:i:s', $cp->post_date);


5

You could easily do this using mysql: DELETE FROM wp_comments WHERE comment_date < DATE_ADD(CURDATE(), INTERVAL -6 MONTH)


5

I don't see anything like it in the database, so you probably have to do this yourself. To save the last login time, you can hook into the wp_login action, and save a user meta value (like [myprefix]_lastlogintime). You first read this value, so you get the previous login time, save this in the session, and then save the new login time. On the regular admin ...


5

Check the Option Reference page. The option gmt_offset returns an integer. For example, if the timezone is set to Easter time, gmt_offset should be -5.


5

As most template tags that start with the_ this one echoes time and not returns it (which template tags that start with get_the_ do). First the_time() fires and echoes year, then its return (null) gets concatenated and echoed with string. So: echo 'Archive for '; the_time('Y'); Or: echo 'Archive for ' . get_the_time('Y');


4

That format is almost readable by strtotime. Remove the commas and it will convert. $t = '27 January, 2012, 5:05 AM'; $t = str_replace(',','',$t); $t = strtotime($t); echo date('Y-m-d H:i:s',$t);


4

Looking at http://www.php.net/manual/en/datetime.formats.date.php I dont think strtotime will convert a DD/MM/YYYY to time correctly. However it can do MM/DD/YYYY or YYYY/MM/DD. Try using the date format of YYYY/MM/DD Or if thats not to your liking then you can use the same date format but you will have to, on save, split up the date and convert it to ...


4

Despite what the Codex says, $postarr doesn't always get passed in, so you should just use $data. $data isn't a meaningful variable name, though, so I prefer $cleanPost. I'd also try removing the priority on the filter, since it's not usually necessary. It's also a good idea to set the slug (post_name) in addition to the title, and to avoid running the code ...


4

You use a lowercase y for a 2 digit year. For example (l, F j, Y) --> returns, Friday, September 24, 2004 and (l, F j, y) ---> returns Friday, September 24, 04


4

Here is the full (I think) list of valid date/time parameters to pass to the_date() and/or the_time().


4

get_the_date and/or get_the_time will return the date/time of the post rather than printing it.


4

I believe all the info you need is in the PHP Manual for Date/Time. Also, it is recommended that you use get_the_date(); instead of the_date(); Get them month in 3 cap letters? M is the right format character that outputs a short textual representation of a month (3 chars). Why can't you use CSS to capitalize all the three letters? I mean, ...


3

The issue is that for correct output WP needs to process date through date_i18n() function. When you use date format, hardcoded in PHP code (not simply saved in PHP DATE_* constant) like 'c' - it's not available to your code and so for WP to process. System-wide fix would be to re-process date with analogous format that can be accessed by WP code: ...


3

$mytimestamp = date(get_option('date_format'), strtotime($date)) . ' at ' . date(get_option('time_format'), strtotime($date));


3

Somehow I missed the current_time function, which gives a good description of the situation and how to properly deal with the need to get the current blog-local time. http://codex.wordpress.org/Function_Reference/current_time Though the purist in me still hates how WP makes the time zone setting in php.ini obsolete without giving you a choice. *grumble ...


3

try $future_timestamp = strtotime('+1 week', get_the_date('Y-m-d')); echo date('Y-m-d', $future_timestamp); or $future_timestamp = get_the_date('U') + (60 * 60 * 24 * 7); echo date('Y-m-d', $future_timestamp);



Only top voted, non community-wiki answers of a minimum length are eligible