如何让$your_date = strtotime("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));
答案 0 :(得分:1)
只需传递变量而不引用。
$your_date = strtotime($started);
即使您的代码也能正常运行,但请尝试删除引号。
答案 1 :(得分: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');