i have a problem with gmdate() not returning the correct time here in the uk, i have a site that runs off a 24/7 schedule that has been off sync since the time change.

this is the code i am using:

gmdate("h:i:s A", time() + 3600*(date("I")))

and various code from the php manual also doesnt work. whats going on, it has been working for over 6 months ???

    What "incorrect" time is it returning, and what is the expected time?

    EDIT: Works fine on my server here in the good ol' US. I used the following code:

    echo gmdate("h:i:s A", time() + 3600*(date("I"))) . "<br><br>" . date("h:i:s A");

    and got the following results:

    11:35:03 PM

    05:35:03 PM

    May it be known that i am GMT-6:00 US Central time..🙂

      Pulled this snippet out of the user comments of the PHP documentation for gmdate:

      Wath out for summer time and winter time...

      If you want to get the current date and time based on GMT you could use this :

      $timezone = -5; //(GMT -5:00) EST (U.S. & Canada)
      echo gmdate("Y/m/j H:i:s", time() + 3600*($timezone+date("I")));

      this would gives: 2004/07/8 14:35:19 in summer time
      and 2004/07/8 13:35:19 in winter time.

      Note that date("I") returns 1 in summer and 0 in winter.

      Hope it helps.

        yeah, i've tried that code and that doesnt work either, the time is always one hour out.

        I think the problem is with the date("I"), it is not returning 1 as i changed the code to

        echo gmdate("Y/m/j H:i:s", time() + 3600*(1)); 
        

        and it worked.

          Your server's own time zone may be configured to UTC, not civil time. What does using date() get you? Standard time or summer time?

            its hard to tell as the admin keeps on switching timezone to make this work.... the server is in NYC but admin'd from Malaysia... i'll ask him about the UTC thing.

              the problem i have worked out is this, because the US is not currently in daylight savings time then date("I") will not return the 1 that is needed to convert gmdate to the right time.

                Ah-ha, so the server is configured to (U.S.) EST. Oh, that reminds me of a wee bit of code I came up with and posted in another forum. You might find it useful.

                  Write a Reply...