Php 日差

Php 日差,php,strtotime,Php,Strtotime,我怎样才能使$your_date=strotime(“2010-01-01”)成为动态的?我是说(“2010-01-01”)a(“动态”) 代码如下: $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; ec

我怎样才能使
$your_date=strotime(“2010-01-01”)
成为动态的?我是说(“2010-01-01”)a(“动态”)

代码如下:

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

“动态”是什么意思?您还没有很好地解释您想要实现的目标。从中删除“”:$your_date=strottime($start);它正在工作..动态意味着..我可以在上面设置sa变量,就像一个rahul答案一样。我的代码已关闭,无法工作..我没有删除$started变量上的“”。单击此答案左上角的上箭头标记和右符号