Hot answers tagged

44

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


18

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


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


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


9

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


9

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


8

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.


7

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


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

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


6

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


6

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


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

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

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

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


5

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


5

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


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

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


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

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



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