Jump to content

Dates Beyond 01-18-2038


kevinfwb

Recommended Posts

I have a function (flipdate) that I use to convert yyyy-mm-dd to mm-dd-yyyy. The code that I am using is: (obtained here - Thank you!)

 

function flipdate($date) {

        if($date == "0000-00-00") return "00-00-0000";

        return date('m-d-Y', strtotime($date));

}

 

 

I found that for some reason, any dates that are beyond 2038-01-18 will display as 01-18-2038.  Anything prior to that date shows up properly.  For example: if the database entry is 2022-05-31, flipdate will display it as 05-31-2022.  However, if the date in the database is 2040-05-31, flipdate outputs 01-18-2038.

 

I've checked the database and the date is stored correctly.  If I remove the flipdate from the echo it will properly show the date 2040-05-31.

 

I'm completely lost on this one.  Any and all help is greatly appreciated.

 

-Kevin

 

Link to comment
https://forums.phpfreaks.com/topic/40401-dates-beyond-01-18-2038/
Share on other sites

Thanks for the info - I was unaware of a 2038 issue with unix systems.

 

A 2 quick follow up questions. 

 

My query is SELECT * FROM TABLE... do I have to manually apply DATE_FORMAT to each field that is a date type or is there a nifty way to apply it to many fields?  I assume this is the case but I figured I'd ask anyway.

 

Secondly can I SELECT *, DATE_FORMAT(date, '%m-%d-%Y) for each DATE type or do I need to specifically select each and every field?

 

I ask because the table contains about 150 fields in which about 75 are dates. 

ehh. Well you do have to specify DATE_FORMAT() for each column. I'm guessing that you are not going to look at all 75 date fields or all 150 fields. You'd be better off just returning the columns you are looking at. And if you were doing this all in PHP,  this is still way less typing that you would have done.

 

I think your locale setting or language can effect how dates are displayed. You may be able to change a system variable and get what you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.