SitePoint Sponsor

User Tag List

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

    date( ) question

    I'm working on a script that uses the time() and date() functions. The system clock is set in EDT (Eastern)time and I need to convert the time and date to PDT (Pacific). I've been able to convert the time OK by subtracting 3 hours from the system time.
    PHP Code:
    $time date("H:i:s"mktime(date("H") - 3)); 
    But I'm having difficulty with the date. After 9PM PDT, the date() function returns a date one day ahead of the date in PDT. So, I somehow need to adjust the date by subtracting 3 hours from the EDT date. (Hope that's clear <g>).

    Any suggestions?

    SeattleDan

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This could help you,

    PHP Code:
    <?php
    $time 
    mktime(0,0,0,10,9,2001);

    $tm1 date("m/j/Y, H:i:s",$time 10800);                 
    $tm2 date("m/j/Y, H:i:s",$time);                 

    echo 
    "$tm1\n";
    echo 
    "$tm2\n";
    ?>
    if you want to use the actual date/time, just replace the $time value by time(), $time = time();

    (if you need further information you can read:
    mktime()
    time()
    date()
    )
    Last edited by Paul S; Oct 9, 2001 at 15:35.

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

    Looks like that will work.


    SeattleDan

  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)
    Dan,

    AS a side note, you'll need to do the same thing with the date as you did with the time, subtract 3 hours from it.


    PHP Code:
    $time date("H:i:s"mktime(date("H") - 3));
    $date date("Y-m-d"mktime(date("H") - 3)); 
    Or

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

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to you, too, Freddy.

    Looks like Paul's code:
    $time = time();
    $tm1 = date("m/j/Y, H:i:s",$time - 10800);

    is equivalent to yours:
    $time = date("Y-m-d H:i:s", mktime(date("H") - 3));


    SeattleDan

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes time() - 10800 is essentially current unixtimestamp minus the number of seconds in three hours. Mine uses mktime() to generate the same number.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by SeattleDan
    Thanks Paul.
    You're welcome

    Actually if you are working only with current time, you can get rid of that temporal variable writing
    PHP Code:
    $tm1 date("m/j/Y, H:i:s",time() - (60*60)*3); 
    (60*60*3 a more explicit way to tell you need a three-hour difference)

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure there are tons of ways of accomplishing the same thing.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Sure there are tons of ways of accomplishing the same thing.


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
  •