获取php中两个日期之间的天数
我试图获取两个日期之间的天数,但返回的结果不正确。这是我的尝试获取php中两个日期之间的天数,php,wordpress,Php,Wordpress,我试图获取两个日期之间的天数,但返回的结果不正确。这是我的尝试 $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
$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
?>
$since_start->d
!=<代码>$since_start->days你能添加一些解释吗?@AdrianCidAlmaguer添加了解释!谢谢,现在对用户更好;-)