0

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?

CHANist
  • 1,302
  • 11
  • 36
  • 1
    Possible duplicate of [PHP & mySQL: Year 2038 Bug: What is it? How to solve it?](http://stackoverflow.com/questions/2012589/php-mysql-year-2038-bug-what-is-it-how-to-solve-it) – sepehr Sep 04 '15 at 06:08

1 Answers1

2

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.

doublesharp
  • 26,888
  • 6
  • 52
  • 73
  • thanks... I have tried it on a 32bit WAMP server, and I see the problem. Just a point to add, when the timestamp exceeds, e.g. setting date('Y-m-d H:i:s', $date1_timestamp), no matter what values I have been choosing in mktime, it as always return to 1970-01-01 01:00:00. – CHANist Sep 04 '15 at 06:24