Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取php中两个日期之间的天数_Php_Wordpress - Fatal编程技术网

获取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添加了解释!谢谢,现在对用户更好;-)