How to get time difference between publish date and now?

Try the date_diff() / DateTime::diff() function in PHP: // Object-oriented style. $datetime1 = new DateTime( $post->post_date ); $datetime2 = new DateTime(); // current date $interval = $datetime1->diff( $datetime2 ); echo $interval->format( ‘%a days old’ ); // .. or procedural style. $datetime1 = date_create( $post->post_date ); $datetime2 = date_create(); // current date $interval = date_diff( $datetime1, … Read more

Relative Time On Posts

WordPress actually has an obscure and little known function called human_time_diff() that does this. It takes two arguments; the first is the earlier timestamp, and the second is the later timestamp. Both should be Unix timestamps. The first argument is required, but the second is optional, and will use time() if left empty. So, for … Read more

Finding difference in days

You should store the time as a unix time stamp then you can use human_time_diff to compare. echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ); If the difference is more than 24 hours difference it will return the value in days.

Is it safe to use ‘date_default_timezone_set’ in plugin file?

http://codex.wordpress.org/Function_Reference/get_gmt_from_date Replace all instances of get_the_date or the_date with echo get_gmt_from_date(get_the_date(‘Y-m-d H:i:s’)). That’s not a quick fix, it’s a way to fix your sitemaps. EDIT: WordPress SEO runs it’s raw dates from MySQL through a WP function called mysql2date, which in turn calls date_i18n. date_i18n happens to have a handy filter which you can tie … Read more

Add 20yrs to post date, and then query

An example, that uses the posts_where filter. If you need to extend a query using the posts_clauses filter, then just exchange $where with $pieces and set $pieces[‘where’] .= instead of $where .=. Just drop that into your functions.php file and add some conditional tag before querying the posts. function filter_where( $where ) { // Add … Read more

Date, Time, and Timezones

What is the purpose of the timezone setting in the Admin -> Settings section? Since WordPress handles time zone on its own (separately from native PHP functionality) that is where the setting made and result is stored in options. Whenever anything that works with timezones needs to happen, the time zone setting is retrieved and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)