如何使$your_date = strtotime("2010-01-01")
成为动态的?我是说(2010-01-01)一个(动态的)?
代码如下:
$started = get_post_meta(get_the_ID(), 'wtf_started', true);
$now = time(); // or your date as well
$your_date = strtotime("$started");
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));
直接传递变量,不加引号。
$your_date = strtotime($started);
即使你的代码也工作得很好但是试着去掉引号
试试这个
$startdate = new DateTime(date("Y-m-d", strtotime(get_post_meta(get_the_ID(), 'wtf_started', true))));
$now = new DateTime("now");
$datediff = date_diff($startdate,$now);
echo $datediff->format('%d days');