Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing dates in PHP beyond 2038

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?

like image 290
Moz Avatar asked Mar 16 '11 00:03

Moz


People also ask

How can I get 30 Day date in PHP?

php $next_due_date = date('05/06/2016', strtotime("+30 days")); echo $next_due_date; ?> But it is returning to "05/06/2016" only!

How can I get previous date in PHP?

To get yesterday's date in PHP simply use the DateTime class and instantiate it with the constructor parameter 'yesterday' Then you can format the DateTime object with the format method.

What does date () do in PHP?

The date/time functions allow you to get the date and time from the server where your PHP script runs. You can then use the date/time functions to format the date and time in several ways. Note: These functions depend on the locale settings of your server.

What is y2k38 problem associated with timestamp and how it can be resolved?

The basic problem is about the computer's capacity to count the time in seconds past to a certain date (01-01-2038). As Unix based systems measure the time in seconds from 1 January 1970, 03:14:07 UTC on 19 January 2038 is equal to 2,147,483,647 seconds after 1 January 1970.


1 Answers

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).

like image 143
mario Avatar answered Sep 23 '22 00:09

mario