ShadowMage Posted July 23, 2010 Share Posted July 23, 2010 Hey guys, I have a weird situation here. I have a custom date formatting function (I didn't write it, my predecessors did) that takes a date string and format string and returns the date in the proper format. Pretty straight forward. Problem is when the date goes beyond January 18, 2038 it quits working. Any dates up to and including 1/18/2038 return correct dates, but anything after that date returns 12/31/1969. What gives?Here's the format function along with a test piece of code: function FormatDateTime($datetime, $format) { /* Formats a date as specified Arguments: $datetime: any textual datetime description $format: format to return; check the PHP date() function for details */ return date($format, strtotime($datetime));}//This one works$testFarOutDate = "2038-01-18";echo $testFarOutDate." => ".FormatDateTime($testFarOutDate, "m/d/Y");//This one doesn't$testFarOutDate = "2038-01-19";echo $testFarOutDate." => ".FormatDateTime($testFarOutDate, "m/d/Y"); Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 end of another Mayan calender? Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 end of another Mayan calender? Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 found it: http://php.net/manual/en/function.date.php 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). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows). Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 found it: http://php.net/manual/en/function.date.phpThe 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). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows). Ah-ha....Well, that makes sense. Only problem now is how do I fix it? Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 upgrade to a 64-bit system.... Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 upgrade to a 64-bit system....Well, that's kind of out of the question so I guess I'm stuck with it.... Oh well, it's not a huge deal. How is that range figured anyways? What happens when we get to 1/19/2038? Granted that's nearly 30 yrs and I'm sure someone will figure out something by then. Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 Well, that's kind of out of the question so I guess I'm stuck with it.... Oh well, it's not a huge deal. How is that range figured anyways? What happens when we get to 1/19/2038? Granted that's nearly 30 yrs and I'm sure someone will figure out something by then. supplemental reading:http://us2.php.net/manual/en/language.types.integer.phpit's based on the number of bits needed to store that much information. Something similar to the fact that a 32-bit OS will only recognize just under 4G of RAM, where as a 64-bit one has enough memory addressing for much more. So its more hardware related, part of it is the processor (needing to be 64-bit) and an OS capable of handling such a processor. As you know, this is very common these days, but older hardware, say a machine running Win XP, will never be able to get to that level. You will already find 64-bit servers out there, its only a matter of time before they too become more common. (which I'm sure will happen sooner than 1/19/2038). For instance Win7 and OSX Snow Leopard are 64-bit compatible (of course when using a 64-bit processor) which I have both of! (for music recording and work). Yes, I am the man. Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 You will already find 64-bit servers out there, its only a matter of time before they too become more common. (which I'm sure will happen sooner than 1/19/2038).By then we'd better have 512-bit architectures or better! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 23, 2010 Share Posted July 23, 2010 FYI, for 64-bit integers, in the negative direction it goes back about 20 times earlier than the beginning of the universe, and in the positive direction it goes for about 293 billion years. That should probably be enough. Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 FYI, for 64-bit integers, in the negative direction it goes back about 20 times earlier than the beginning of the universe, and in the positive direction it goes for about 293 billion years. That should probably be enough.Are those real figures or are you exagerating? Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 FYI, for 64-bit integers, in the negative direction it goes back about 20 times earlier than the beginning of the universe, and in the positive direction it goes for about 293 billion years. That should probably be enough.i guess if that's the best they can do... Link to comment Share on other sites More sharing options...
justsomeguy Posted July 23, 2010 Share Posted July 23, 2010 Those are real figures. A 33-bit number would provide twice the size of a 32-bit number. A 34-bit number would provide 4 times the size. A 64-bit number provides 2^32 times the size. A 32-bit number provides +/- 68 years, so a 33-bit number would be +/- 132 years. Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 Ok wow. I guess 293 billion years might be enough.... Link to comment Share on other sites More sharing options...
music_lp90 Posted July 23, 2010 Share Posted July 23, 2010 You might be a web programmer if someone tells you they are having troubles with strange date behavior and your solution is to upgrade to a 64-bit system. Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 23, 2010 Share Posted July 23, 2010 You might be a web programmer if someone tells you they are having troubles with strange date behavior and your solution is to upgrade to a 64-bit system.I'm a strange date, so I'm really getting a kick out of this. Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 Link to comment Share on other sites More sharing options...
ShadowMage Posted July 23, 2010 Author Share Posted July 23, 2010 :) Link to comment Share on other sites More sharing options...
thescientist Posted July 23, 2010 Share Posted July 23, 2010 great thread, or greatest thread? Link to comment Share on other sites More sharing options...
Synook Posted July 24, 2010 Share Posted July 24, 2010 By then we'd better have 512-bit architectures or better! Interestingly enough, http://www.google.com.au/search?q=windows+8+128+bit. But yes, for all current purposes 64 bits are fine.And guys, stop spamming ... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.