显示一个日期和今天之间的天数

时间:2012-10-09 13:03:19

标签: php date

  

可能重复:
  How to find number of days between two dates using php
  Days left - subscription expire?

我的代码应该回显从日期(2012-10-01)到今天的天数。

$datetime1 = date_create('2012-10-01');
$datetime2 = date_create();

$day1 = date_format($datetime1, 'Y-m-d');
$day2 = date_format($datetime2, 'Y-m-d');    

$day = $day2 - $day1 / (60 * 60 * 24);
echo $day;

我无法得到任何正确的解决方案,所以任何想法我应该怎么做?

1 个答案:

答案 0 :(得分:0)

查看Finding the number of days between two dates

以下示例代码(适用于您的日期):

$now = time();
$your_date = strtotime('2012-10-01');
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));