PHP: does date have GMT offset?

Discussion in 'Web Design and Development' started by MacDonaldsd, Feb 16, 2008.

  1. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #1
    Hi all,

    Im manipulating dates in PHP and then saving them for latter use in the GMT format.

    (I will be using it in RSS in the format Wed, 13 Feb 2008 17:22:00 GMT).

    The problem is when you store a date you do not get the exact time in the summer as it is 1hour ahead so you have to put for example:

    Sun, 1 Jun 2008 14:00:00 GMT -0100

    Is there anyway of finding out using php whether daylight saving is in effect on the given date so the appropriate adjustment can be made ?
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    You can check if daylight savings is in effect. http://us3.php.net/gmdate Do a search for daylight on this page and you'll find an example. Essentially date("I"); will return 1 is daylight savings is current, 0 otherwise.
     
  3. MacDonaldsd thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #3
    Thanks for that but I have a problem it always returns 0

    First is of each date is done using date()
    Seconds using gmdate()


    Jun 01 2008 00:00:00 0
    Jun 01 2008 07:00:00 0

    Jan 01 2008 00:00:00 0
    Jan 01 2008 07:00:00 0

    Code:
    echo date("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
    echo "<br/>";
    echo gmdate("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
    echo "<br/>";
    echo "<br/>";
    
    echo date("M d Y H:i:s I ", mktime(0, 0, 0, 1, 1, 2008));
    echo "<br/>";
    echo gmdate("M d Y H:i:s I", mktime(0, 0, 0, 1, 1, 2008));
    echo "<br/>";
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    I ran your PHP and get,

    Jun 01 2008 00:00:00 1
    Jun 01 2008 04:00:00 0

    Jan 01 2008 00:00:00 0
    Jan 01 2008 05:00:00 0


    So I'm getting thr correct results ... for whatever reason. Maybe it's a server setting then.
     
  5. MacDonaldsd thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #5
    Thanks I appreciate the help :D

    I get my results both on my mac and on my go daddy hosting account, im surprised they both give incorrect values.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  7. MacDonaldsd thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #7
    yeah that works:

    Code:
    <?php
    date_default_timezone_set('Europe/London');
    
    
    echo date("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
    echo "<br/>";
    echo gmdate("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
    echo "<br/>";
    echo "<br/>";
    
    echo date("M d Y H:i:s I ", mktime(0, 0, 0, 1, 1, 2008));
    echo "<br/>";
    echo gmdate("M d Y H:i:s I", mktime(0, 0, 0, 1, 1, 2008));
    echo "<br/>";
    ?>

    Produces

    Jun 01 2008 00:00:00 1
    May 31 2008 23:00:00 0

    Jan 01 2008 00:00:00 0
    Jan 01 2008 00:00:00 0

    Thanks for your help angelwatt
     

Share This Page