viion Posted May 9, 2011 Share Posted May 9, 2011 I'm having a weird issue going on, I'm wondering if it has to do with my php.ini or server setup, anyway here is the code with the odly outcomes: echo date('Y/m/d H:i:s', 2145000000); // 2037/12/21 01:20:00 echo date('Y/m/d H:i:s', 2149000000); // 1901/12/31 01:58:24 echo date('Y/m/d H:i:s', 2150000000); // 1902/01/11 15:45:04 It seems after year 2037 it goes down to 1900+... Why would this happen? I've tried on 2 godaddy servers and local host and all same result Quote Link to comment https://forums.phpfreaks.com/topic/235970-issue-with-date-from-timestamp/ Share on other sites More sharing options...
requinix Posted May 10, 2011 Share Posted May 10, 2011 It's called integer overflow: 2147483647+1 = -2147483648. echo date('Y/m/d H:i:s', 2147483647); echo date('Y/m/d H:i:s', 2147483648); echo date('Y/m/d H:i:s', -2147483648); 2038/01/18 19:14:07 (US Pacific coast) 1901/12/13 12:45:52 1901/12/13 12:45:52 See also: the Y2K38 bug. Quote Link to comment https://forums.phpfreaks.com/topic/235970-issue-with-date-from-timestamp/#findComment-1213121 Share on other sites More sharing options...
viion Posted May 10, 2011 Author Share Posted May 10, 2011 Ah, damn I forgot that. Anyway I can get around it? Quote Link to comment https://forums.phpfreaks.com/topic/235970-issue-with-date-from-timestamp/#findComment-1213155 Share on other sites More sharing options...
viion Posted May 10, 2011 Author Share Posted May 10, 2011 Cant edit my post, marking solved as I've found a work around. Thank you for enlightment! Quote Link to comment https://forums.phpfreaks.com/topic/235970-issue-with-date-from-timestamp/#findComment-1213167 Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 Just for completeness the answer to this question is to use the php DateTime class which is not limited in range to 32 bit timestamps. Quote Link to comment https://forums.phpfreaks.com/topic/235970-issue-with-date-from-timestamp/#findComment-1213206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.