我正在尝试获取两个日期之间的天数,但返回的结果不正确。这是我的尝试;
$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
我哪里出错了?它适用于前几个帖子,但随后会在月份更改时重新启动。
答案 0 :(得分:1)
试试这个
i
答案 1 :(得分:0)
试试这个。
<?php
$currentTime = time();
$startTime = strtotime("YYYY/MM/DD");
$diff = $currentTime - $startTime;
echo floor($diff/(60*60*24)); // Number of days between $currentTime and $startTime
?>