I have PHP version 5.3.10-1ubuntu3.10.

I am specifying date as "2090-11-29 05:00:00" and using strotime to print and compare it with Current date. But it returns "Blank Value"

Here is my Code :

<?php
    $dateTime = "2003-04-19 11:00:00";
    $mdate = strtotime($dateTime);
    $ndateTime = "2090-11-29 05:00:00";
    $ndate = strtotime($ndateTime);

    echo $ndate.' - <br />';

    if(($date > $mdate) && ($date < $ndate)) {
        echo $date.' is greater than  '.$ndate . ' First ';
    } else {
        echo $ndate.' is greater than  '.$date;
    }

    echo '<br />';
    echo phpversion();
?>
有帮助吗?

解决方案

the max date you can get is 2038, check the year 2038 problem for more information about this issue. Now to solve the problem -- as @Mike suggested -- you can use DateTime objects, consider the following example:

$date =new DateTime("2090-11-29 05:00:00");
echo $date->format('Y-m-d H:i:s'); //will output 2090-11-29 05:00:00

and you can set the format as you wish and there are enough examples found in the php documentation Also settimezone function for datetime object

其他提示

You can use DateTime, which supports bigger dates than the regular time functions on 32-bit machines; its constructor supports the same format as strtotime() so conversion should be straightforward.

However, in this case a simple string comparison will accomplish the same thing, because the Y-m-d H:i:s format is suitable for comparisons of dates until Y10k.

$mdateTime = "2003-04-19 11:00:00";
$ndateTime = "2090-11-29 05:00:00";
$date = '2013-03-11';

if ($date > $mdateTime && $date < $ndateTime) {
    // $date is between $mdateTime and $ndateTime
} else {
    echo $ndate.' is greater than  '.$date;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top