31

I know I'm three months late, but the function you want here is WordPress' 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-...


21

If you don't add a post_date then WordPress fills it automatically with the current date and time. To set another date and time [ Y-m-d H:i:s ] is the right structure. An example below with your code. $postdate = '2010-02-23 18:57:33'; $new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_date' => ...


21

I ran into the same problem several times, following changes worked for me in the past: while (have_posts()) : the_post(); //some html <li class="icon-date"><?php echo get_the_date( 'Y-m-d' ); ?></li> <li class="icon-time"><?php the_time( 'H:i:s' ); ?></li> Instead of the_date(), use get_the_date(). The only thing to be ...


15

The unfortunate situation is that there are indeed two different options: Newer timezone_string, which saves PHP–style time zone. Older gmt_offset, which saves numeric float offset in hours. But in newer environments timezone_string actually overrides gmt_offset, the value returned by the latter will be based on the former. However the opposite isn't true —...


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

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


8

I'm not sure why EliasNS' answer is marked correct, as far as I'm aware (and from the documentation), the second parameter of DateTime::__construct(), if provided, should be a DateTimeZone instance. The problem then becomes, how we do we create a DateTimeZone instance. This is easy if the user has selected a city as their timezone, but we can work around it ...


7

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 ...


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 WP ...


7

Here are two ideas for your date_query part: 1) After 2 days ago: If you need posts published after current time, 2 days ago: 'date_query' => array( array( 'after' => '2 days ago', // or '-2 days' 'inclusive' => true, ), ), then the corresponding SQL part is: post_date >= '2014-09-09 17:57:15' if the ...


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 it ...


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';


6

According to the Codex page for get_the_time(), it needs to be used in The Loop. The difference between the_time() and get_the_time() is that the former echo()es the date, and the latter returns it. There are a couple functions that do what I think you're looking for -- get the last updated date and time for a post: get_the_modified_time() and ...


6

You're almost there. The number you see is a called Unix Timestamp. You can easily convert it using date_i18n like this: <?php echo date_i18n(get_option( 'date_format' ), $text); ?>


6

The date/time related field types for CMB2 store all their values as Unix timestamps in the database with the exception of text_datetime_timestamp_timezone which stores it's value as a serialized DateTime object. text_date_timestamp Date Picker (UNIX timestamp) text_datetime_timestamp Text Date/Time Picker Combo (UNIX timestamp) ...


6

date() is a PHP function depending on your server settings. You can go around that by using the WordPress function: current_time( 'Y-m-d H:i:s' ); This function takes the settings in wp-admin into account.


5

From the codex: current_time('timestamp') should be used in lieu of time() to return the blog's local time. In WordPress, PHP's time() will always return UTC and is the same as calling current_time('timestamp', true). Try this: define( 'MY_TIMEZONE', (get_option( 'timezone_string' ) ? get_option( 'timezone_string' ) : date_default_timezone_get() ) );...


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

Here's a sketch of another idea, where we create scheduling shortcuts to make it easier for the users: We can use the post_submitbox_misc_actions to add extra fields to the submit box: /** * Scheduling-Shortcuts fields. * * @see http://wordpress.stackexchange.com/a/168748/26350 */ add_action( 'post_submitbox_misc_actions', function() { if( ! ...


5

I don't think there is a parameter value Today as you used in date_query. If you want to return today's post then you should provide date value to date_query as you stored current date in $today array. So here is your query now. $today = getdate(); $args = array( 'tag_slug__in' => array( 'destacado'), 'posts_per_page' => 2,...


5

Loosely what you have should work already. However few things are off. Calling these function without time format will produce values like 1:36 pm (depending on your site's settings), which are not exactly comparable. Post modified time can be less than published in some cases, like scheduled posts. So I would write it along the lines of: if ( ...


4

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: ...


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, text-transform:...


4

wp_schedule_event can not be used for PRECISE time measurements as you are trying to do. An event scheduled with wp_schedule_event rarely runs exactly when it is scheduled to run, it runs sometime after the time which it has been configured for. To understand this, you must understand that php doesn't know what time it is until you ask it to look. Wordpress ...


4

It is unclear if you are looking for the last updated post or for the last updated date for some particular post. The answer by @PatJ assumes the former. To do the latter: $qry = new WP_Query(array('p'=>1)); var_dump($qry->posts[0]->post_modified); Or... $date = $wpdb->get_var("SELECT post_modified FROM {$wpdb->posts} WHERE ID = 1"); ...


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

General WordPress rule: when a function starts with get, it will return the value. If it starts with the, it echoes the value. Here, you need get_the_date('d-m-Y') instead of the_date('d-m-Y').


4

Use date_i18n( $format, $i ); echo date_i18n('j F Y', strtotime( $event_date[0] ) ) . ' ' . date_i18n('j F Y', strtotime( $event_from_time[0] ) ) . ' do ' . date_i18n('j F Y', strtotime( $event_to_time[0] ) ); See also: How to integrate get_post_time with date_i18n function?


4

From the comments in the WP_Post class in wp-includes/post.php: You can set the post date manually, by setting the values for 'post_date' and 'post_date_gmt' keys. So if you're adding a post programmatically, and you want a date attached, you should set both keys. (If you leave them blank, WordPress will use the appropriate current date for both.)


4

1) Using only the posts_orderby filter: It looks like you want to order the movies by the minimum of the wpcf-showtime meta values. You can modify the ORDER BY part of the SQL generated by the WP_Query, by using the posts_orderby filter. Here's an example: add_filter( 'posts_orderby', 'wpse_posts_orderby' ); $ongoing_movies = new WP_Query( $args ); ...


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