kevinfwb Posted February 27, 2007 Share Posted February 27, 2007 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 More sharing options...
fert Posted February 27, 2007 Share Posted February 27, 2007 http://en.wikipedia.org/wiki/Year_2038_problem Link to comment https://forums.phpfreaks.com/topic/40401-dates-beyond-01-18-2038/#findComment-195486 Share on other sites More sharing options...
artacus Posted February 27, 2007 Share Posted February 27, 2007 Unix timestamps "run out" in 2038 and the whole world grinds to a halt. Don't bother with this. Just use mysql's DATE_FORMAT(dateField, '%m-%d-%Y') which skips the whole unix timestamp thing. Link to comment https://forums.phpfreaks.com/topic/40401-dates-beyond-01-18-2038/#findComment-195492 Share on other sites More sharing options...
kevinfwb Posted February 27, 2007 Author Share Posted February 27, 2007 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. Link to comment https://forums.phpfreaks.com/topic/40401-dates-beyond-01-18-2038/#findComment-195522 Share on other sites More sharing options...
artacus Posted February 27, 2007 Share Posted February 27, 2007 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. Link to comment https://forums.phpfreaks.com/topic/40401-dates-beyond-01-18-2038/#findComment-195547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.