PDA

View Full Version : [SOLVED] php date() wrong for november??



Duffman12
10-23-2009, 04:47 PM
I have a calender I made in php. I use a timestamp for each day and increment it by 24 hours each time. The date function seems to be returning the wrong thing for novemeber, however:


Oct 30, 2009 = date("M j, Y", 1256875200)
Oct 31, 2009 = date("M j, Y", 1256961600)
Nov 1, 2009 = date("M j, Y", 1257048000)
Nov 1, 2009 = date("M j, Y", 1257134400)
Nov 2, 2009 = date("M j, Y", 1257220800)
Nov 3, 2009 = date("M j, Y", 1257307200)

to check the timestamps, I'm using http://www.onlineconversion.com/unix_time.htm. Here's what that site has to say:


Oct 30, 2009 = date("M j, Y", 1256875200) Fri, 30 Oct 2009 04:00:00 GMT
Oct 31, 2009 = date("M j, Y", 1256961600) Sat, 31 Oct 2009 04:00:00 GMT
Nov 1, 2009 = date("M j, Y", 1257048000) Sun, 01 Nov 2009 04:00:00 GMT
Nov 1, 2009 = date("M j, Y", 1257134400) Mon, 02 Nov 2009 04:00:00 GMT
Nov 2, 2009 = date("M j, Y", 1257220800) Tue, 03 Nov 2009 04:00:00 GMT
Nov 3, 2009 = date("M j, Y", 1257307200) Wed, 04 Nov 2009 04:00:00 GMT

what's the deal with date()???

[update]

Oct 24, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256356800)
Oct 25, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256443200)
Oct 26, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256529600)
Oct 27, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256616000)
Oct 28, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256702400)
Oct 29, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256788800)
Oct 30, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256875200)
Oct 31, 2009 00:00:00 am = date("M j, Y H:i:s a", 1256961600)
Nov 1, 2009 00:00:00 am = date("M j, Y H:i:s a", 1257048000)
Nov 1, 2009 23:00:00 pm = date("M j, Y H:i:s a", 1257134400)
Nov 2, 2009 23:00:00 pm = date("M j, Y H:i:s a", 1257220800)
Nov 3, 2009 23:00:00 pm = date("M j, Y H:i:s a", 1257307200)

this might be a timezone issue?

i'm still incrementing by 24 hours though, so it shouldn't make a different, right?

$day_marker += (24*60*60); // get tomorrow


[update]
I fixed it by adding:

date_default_timezone_set('UTC');
although, i'm not exactly sure why this fixed it...

[update]
daylight savings!! i guess my server was on eastern standard time. the clocks go back 1 hour on the first sunday in november. UTC time doesn't have daylight savings, so it's good to use that. noted.