SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date & time question

    I have set date and time variables by using:
    $date = date("Y-m-d");
    $time = date("H:i:s");

    This will give me the date and time according the system time on my server, which uses Eastern Daylight Time.

    However, I want to display the date and time on my web page showing Pacific Daylight Time. In other words, I want to show a date and time that is 3 hours less than the time returned by the statement above.

    How can I modify my statements above to return the date and time minus 3 hours?

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use date('H:i:s', time() - 3*60*60);

    time() returns the current unix timestamp in seconds, and subtracting 3*60*60 is the equivalent of knocking the clock back by three hours.

    If that doesn't work use date('H:i:s', time() + 3*60*60);

    (I can never be bothered to figure out if I should add or subtract the seconds, but trial and error sorts that out )

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Skunk,

    Your first option was the one I needed. It worked just the way I wanted.

    Thanks!

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While it does the same thing, it may be easier to manage using mktime()


    PHP Code:
    $time date("H:i:s"mktime(date("H") - 3)); 
    Which basically does what Skunk's code does but using mktime() you can subtract 3 hours. mktime() takes 5 optional args, starting with hour, minute, second, month,day,year if any are left out on the right it takes the current values of each one. So that example would produce the same result as

    PHP Code:
    $time date("H:i:s"mktime(date("H") - 3date("i"), date("m"), date("d"), date("Y")); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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