如何计算过去3个月的天数

时间:2013-11-11 09:36:49

标签: php date

我们如何计算,过去3个月的天数?

即。 - 今天是11-11-2013

我想计算从1st Septembertoday的总天数;即72天。

11月1日将自动更改。

5 个答案:

答案 0 :(得分:1)

<?php

     $now = time(); // or your date as well
     $your_date = strtotime("2010-01-01");
     $datediff = $now - $your_date;
     echo floor($datediff/(60*60*24));

?>

您还可以查看 this link

答案 1 :(得分:1)

准确的时间试试这个

$datetime1 = new DateTime('2013-09-01 12:00:00');
$datetime2 = new DateTime('2013-11-11 12:00:00');
$interval = $datetime1->diff($datetime2);

echo $interval->m . " Month " .$interval->d ." Days ". $interval->h . " Hours, " . $interval->i." Mintues, ".$interval->s." seconds "; 

答案 2 :(得分:0)

试试这个:

date('d') + cal_days_in_month(CAL_GREGORIAN, date('m') -1 , date('y')) + cal_days_in_month(CAL_GREGORIAN, date('m') -2 , date('y'));

答案 3 :(得分:-1)

$currentDate = mktime(0, 0, 0 , date("m"), date("d"), date("Y"));<br/>
$last3Months = mktime(0, 0, 0, date("m") - 3, date("d"), date("Y"));<br/>
$diff = $currentDate - $last3Months;<br/>
echo $diff/(60*60*24);

答案 4 :(得分:-1)

$today  =   strtotime("+1 day");
$beforeThreeMonth   =   date("M-Y",strtotime("-2 month"));
$beforeThreeMonthDate   =   strtotime($beforeThreeMonth);

$timeStampInterval  =   $today-$beforeThreeMonthDate;

echo floor($timeStampInterval/(60*60*24));