Accessing dates in PHP beyond 2038

Moz picture Moz · Mar 16, 2011 · Viewed 19.4k times · Source

I am of of the understanding that due to the nature that PHP represents dates using milliseconds, you cannot represent dates past 2038. I have a problem where I want to calculate dates far in the future. Thousands of years away.

Obviously I cannot use the php date function to represent this date because of the limit, however, I have something on my side... All I want to do is store the year, month and day. I do not care for the hour, minute, seconds and milliseconds.

Am I correct in thinking that without including this additional information I should be able to calculate a lot further into the future because I am willing to discard a lot of information. Is this any library that currently does this? If not does any have any advice on how to approach this problem?

Answer

mario picture mario · Mar 16, 2011

You can alternatively use the DateTime class, which internally represents the time components independently. Thus it is not susceptible to the 2038 limitation (unless you use ::getTimestamp).