How to calculate days till some point in future in PHP?

前端 未结 4 1639
野的像风
野的像风 2021-01-18 10:42

I\'ve a date like this: 2011-01-28 00:37:15. What would be the most efficient way to get days from now till this date? I want like number of full days till this

相关标签:
4条回答
  • 2021-01-18 10:50
    <?php
    $datetime1 = new DateTime('2011-01-28 00:37:15');
    $datetime2 = new DateTime('now');
    $interval = $datetime1->diff($datetime2);
    echo $interval->format('%R%d days');
    ?>
    
    0 讨论(0)
  • 2021-01-18 10:55
    <?
    
    $date = "2011-01-28 00:37:15";
    $date_2 = date("Y-m-d H:i:s");
    $date_diff=(strtotime($date)-strtotime($date_2)) / 86400;
    
    ?>
    
    0 讨论(0)
  • 2021-01-18 10:59

    Looks like this should help:

    http://www.prettyscripts.com/code/php/php-date-difference-in-days

    0 讨论(0)
  • 2021-01-18 11:15

    Have a look at http://de.php.net/manual/de/datetime.diff.php (PHP >=5.3.0)

    This will return you a DateIntervall wich has a public attribute days

    0 讨论(0)
提交回复
热议问题