Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date() only from 1970 - 2038

Tags:

date

php

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?

like image 371
Steve Robbins Avatar asked Jul 27 '11 00:07

Steve Robbins


2 Answers

It's 2038 problem

and look, I'm in year 1653

like image 104
genesis Avatar answered Sep 27 '22 21:09

genesis


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.

like image 37
Christopher Armstrong Avatar answered Sep 27 '22 21:09

Christopher Armstrong