5

First off, this is not a question about how to fix a problem because my date is outputting 1969.

This is a question about why time does not exist before 1970 or after 2038 when using date().

I've tried seaching SO and Google but all that turns up is people getting errors when using date() incorrectly, resulting in the familiar output of December 31, 1969 5:00 pm

Does anyone know why it can't go before 1970? Should we stop using date() since it will be unusable after 2038? What's the history on this? What's the work around for working with dates outside of this range?

Steve Robbins
  • 13,672
  • 12
  • 76
  • 124

3 Answers3

4

This is explained on the PHP manual page for date():

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer).

The fact that you're getting December 31, 1969 means that you're likely supplying an odd timestamp parameter to date(), resulting in a date that isn't what you expect. Like @Mitch Wheat said in his comment, this relates to Unix time since it is relative from January 1, 1970.

Christopher Armstrong
  • 7,907
  • 2
  • 26
  • 28
4

It's 2038 problem

and look, I'm in year 1653

Community
  • 1
  • 1
genesis
  • 50,477
  • 20
  • 96
  • 125
  • Very nice, but trying to use `strtotime` on anything less than UTC won't output a negative. Is there a way to fix that? – Steve Robbins Jul 27 '11 at 00:55
  • @imoda: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) – genesis Jul 27 '11 at 01:00
  • 2
    @imoda: I'm on amd64 Debian, that may be your problem. From documentation "The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a **32-bit signed integer**) Additionally, **not all platforms support negative timestamps**, therefore your date range may be limited to no earlier than the Unix epoch." – genesis Jul 27 '11 at 01:04
3

Compare the number 2^31 and the number of seconds between the two date.