获取php中两个日期之间的天数
问题描述:
我试图获取两个日期之间的天数,但返回的结果不正确。这是我的尝试;获取php中两个日期之间的天数
$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
我哪里出错了?它适用于前几个帖子,但是当月份发生变化时它会重新启动。
答
试试这个。
<?php
$currentTime = time();
$startTime = strtotime("YYYY/MM/DD");
$diff = $currentTime - $startTime;
echo floor($diff/(60*60*24)); // Number of days between $currentTime and $startTime
?>
答
试试这个
<?php
$now = time(); // Current time
$your_date = strtotime("2013-12-01"); // This will parses an English textual datetime into a Unix timestamp
$datediff = abs($now - $your_date);// Gives absolute Value
echo floor($datediff/(60*60*24)); //Returns the lowest value by rounding down value
?>
[** ** RTM(http://php.net/manual/en/class.dateinterval.php)'$ since_start-> D'!= ='$ since_start-> days' Rizier123