$t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post ); //date of post
$start_date = new DateTime(); //current date
$since_start = $start_date->diff(new DateTime($t_time)); //difference
echo $since_start->d; //number of days
我哪里做错了?它适用于前几篇文章,但当月份发生变化时它会重新启动。
尝试这个
<?php
$now = time(); // Current time
$your_date = strtotime("2013-12-01"); // This will parses an English textual datetime into a Unix timestamp
$datediff = abs($now - $your_date);// Gives absolute Value
echo floor($datediff/(60*60*24)); //Returns the lowest value by rounding down value
?>