Tutorial

Is Your PHP Application Affected by the Y2K38?

What if you run below php code in your system?

[cc lang=”php”]
‘, date($format, $mydate1), ‘

‘;
?>
[/cc]

With luck, you’ll see “Wednesday 1 February 2040 00:00” displayed in your browser. If you’re seeing a date in the late 60’s or early 70’s, your PHP application may be at risk from the Y2K38 bug!

What is the Y2K38 bug?

The year 2038 problem (also known as Unix Millennium Bug, Y2K38 or Y2.038K by analogy to the Y2K problem) may cause some computer software to fail before or in the year 2038.

Y2K38, or the Unix Millennium Bug, affects PHP and many other languages and systems which use a signed 32-bit integer to signify dates as the number of seconds since 00:00:00 UTC on 1 January 1970. The furthest date which can be stored is 03:14:07 UTC on 19 January 2038. Beyond that, the left-most bit is set and the integer becomes a negative decimal number or a time prior to the epoch.

However, developers thought that way about the Millennium bug the 1970’s and 80’s. Also, any web application which handles long-term future events could be at risk. For example, a typical mortgage runs for 25 years. Pensions and savings plans can be far longer.

Are there alternative options?

Fortunately, PHP introduced a new DateTime class in version 5.2 (experimental support was available in 5.1 and be aware that some methods were introduced in 5.3)

[cc lang=”php”]
‘, $mydate2->format($format), ‘

‘;
?>
[/cc]

DateTime does not suffer from Y2K38 problems and will happily handle dates up to December 31, 9999. I might have paid off my mortgage by then!
It may not be worth upgrading existing applications, but you should certainly consider the DateTime class when planning your next project.

Read Full Article at : Site Point

Shares:
  • Bachor
    Bachor
    September 26, 2010 at 8:26 am

    Wow, that was a good read through. Finally, somebody who really thinks and understands what they’re writing about. Quite rare nowadays, especially on the net. I saved your website and will make sure to keep coming back here if this is how you usually post. Thanks, keep it up!

    Reply
    • buggedcom
      buggedcom
      May 19, 2011 at 12:04 am

      This DateTime stuff is interesting. I didn’t realise there was a coming apocalypse that I should be aware of. So thanks.

      Reply
  • Anthony
    May 16, 2011 at 9:05 pm

    If it is y2k38 and the entire world hasn’t been moved to sixty four bit registers for integers then I could see this being a problem.

    Reply
  • […] via Is Your PHP Application Affected by the Y2K38? | Xpert Developer. […]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *