如何找出两个日期之间的天数

时间:2016-02-10 06:16:28

标签: php

我试图获得两个给定日期之间的天数,但尝试这种方式时却没有给出天数。

{{1}}

它不起作用,没有给出给定两个日期之间的天数。

5 个答案:

答案 0 :(得分:1)

试试这个。这很简单。

   <?php

     $date1 = strtotime("2015-11-16 10:01:13");
     $date2 = strtotime("2015-05-06 09:47:16");
     $datediff = $date1 - $date2;
     echo floor($datediff/(60*60*24))." days"; //output 194 days

    ?>

答案 1 :(得分:1)

使用DateTime类更好,你可以在PHP manual看到评论(9),因为它回答了你的问题

答案 2 :(得分:0)

试试这个,

    $pur_dt = date_create('2015-08-03');
    $todate = date_create(date('Y-m-d'));
    $datediff = $pur_dt - $todate;
    $diff = $datediff/(60*60*24);
    if($diff>15) //checking condition if $pur_dt - $todate > 15
     {
       echo 'Hello you are not eligible';
     }
    else
     {
       echo 'eligible';
     }

答案 3 :(得分:0)

试试这个:

$pur_dt = Date('2015-08-03');

$todate = Date(date('Y-m-d'));


$pur_dt = strtotime($pur_dt);
$todate = strtotime($todate);

$seconds_diff = $todate - $pur_dt;

$$diff = floor($seconds_diff/(60*60*24));

if($diff>15) //checking condition if $pur_dt - $todate > 15
{
    echo 'Hello you are not eligible';
}
else
{
    echo 'eligible';
}

答案 4 :(得分:0)

试试这个

$pur_dt = date_create('2015-08-03');

$todate = date_create(date('Y-m-d'));

$diff = date_diff($todate,$pur_dt);
print_r($diff);
echo $diff->format('%R%a days');
if($diff->days>15) //checking condition if $pur_dt - $todate > 15
{
    echo 'Hello you are not eligible';
}
else
{
    echo 'eligible';
}