2

如何制作$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));
4

2 回答 2

1

试试这个

$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');
于 2013-02-28T09:03:13.373 回答
1

只需传递不带引号的变量。

$your_date = strtotime($started);

即使您的代码也可以正常工作,但请尝试删除引号。

于 2013-02-28T08:42:02.267 回答