33

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


22

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


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


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


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


8

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


8

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.


7

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


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


7

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

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


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); ?>


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

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

You should use date_i18n(): $timestamp = get_post_meta($post_to_edit->ID, '_single_date', true); $friendly_date = date_i18n( get_option('date_format'), $timestamp ); ?><input value="<?= $friendly_date ?>" name="_single_date" />


5

WordPress has a special function for translating dates, called date_i18n. General usage: echo date_i18n( $dateformatstring, $unixtimestamp, $gmt); Supposing you have German as your site's language this would be: echo date_i18n( 'j. F Y', false, false); You can also import the time format from the admin settings, like this: echo date_i18n(get_option('...


5

There should not be any need to do this. Even if an ACF Field is using 'return_format' => 'm/d/Y g:i a', The post_meta value is in YYYY-MM-DD 00:00:00 format. $date_now = date('Y-m-d'); $args = [ 'meta_key'=>'the_date', 'meta_value'=>$date_now.' 00:00:00', 'meta_compare'=>'>=', ]; $query = new WP_Query( $args ); Edit: I've noticed ...


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

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

to convert your date into Wordpress (MySQL DATETIME) format, try this: $date_string = "Sept 11, 2001"; // or any string like "20110911" or "2011-09-11" // returns: string(13) "Sept 11, 2001" $date_stamp = strtotime($date_string); // returns: int(1000166400) $postdate = date("Y-m-d H:i:s", $date_stamp); // returns: string(19) "2001-09-11 00:00:00" $...


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

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


4

This is not a WordPress question, but to help you out: function displaydate() { return date( 'd/m/Y G:i', strtotime( '-6 hours' ) ); } add_shortcode('date', 'displaydate'); The shortcode itself should work fine.


4

It seems that CMB2 is sabving dates in unix timestamp format, which IMHO, is a really good thing. This makes sorting and searching a breeze when you need to sort or search data according to dates. It is really easy to convert unix timestamps into any needed format. As from PHP 5.3, you can use the DateTime class for these type of convertions $text = ...


4

You should use strtotime to turn the comment's date into a string that can be compared with the current time. In your case, you should use: echo human_time_diff( strtotime( $comment->comment_date ), current_time( 'timestamp', 1 ) );


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