phptimestampyear2038

PHP Year 2038 Not a Bug?


I am new to PHP and from the book that I am reading, I realize there is a year 2038 problem, which states that when I use timestamp, the furthest date I can reach will be Jan 19, 2038. In order to overcome this constraint, I am suggested to use dateTime object. However, when I test it in PHP (using MAMP with PHP 5.6.6), it seems that even if I use timestamp on a bigger date, it works perfectly.

For example, note the below code:

    <?php
        $date1_timestamp = mktime(13, 30, 0, 1, 12, 2049);
        $date1 = date('Y-m-d H:i:s', $date1_timestamp);
        echo $date1; // output: 2049-01-12 13:30:00
    ?>

I want to ask why do my PHP server does NOT suffer from year 2038 problem? Why it can output the correct value? Timestamp cannot hold such a big value, right?


Solution

  • This is only an issue for 32 bit version of PHP, you are likely running a 64 bit version which is able to address a greater number of milliseconds, thus represent a timestamp with a value further in the future than the year 2038.