Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Posts
    124
    Thanks
    7
    Thanked 0 Times in 0 Posts

    [SOLVED] php date() wrong for november??

    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:

    Code:
    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:

    Code:
    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]
    Code:
    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?
    Code:
    $day_marker += (24*60*60); // get tomorrow

    [update]
    I fixed it by adding:
    Code:
     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.
    Last edited by Duffman12; 10-24-2009 at 04:15 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •