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 4 of 4

Thread: Date

  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Date

    Got my website almost complete but hvaing problems deciding what to do with the Date and the way to manage the timestamps in the mysql database. The server seems to be +2hrs and as most of my timestamps or updated on current by the database, ive been trying to convert the timestamps -2hrs.

    Only problem is im trying to get the timestamp from the database -2hrs and display it in the correct format.

    Code:
    while($lastactive_row = @mysql_fetch_array($lastactive_result))
    {
    $lastactive_username = $lastactive_row["username"];
    $lastactive_date = date("d M y H:i", strtotime($lastactive_row["last_active"]));
    just dont know the best way to do this, i thought that it was just a matter of adding -2hours before or after $lastactive_row["last_active"] but its not working.

    Any ideas?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    What time format is $lastactive_row['last_active'] in(Unix timestamp, MySQL DATETIME, etc.)?

    If the code you have now is showing the time +2hours you should be able to use this:
    PHP Code:
    $lastactive_date date('d M y H:i'strtotime($lastactive_row['last_active']) - 7200); 

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cozzy1984 View Post
    Got my website almost complete but hvaing problems deciding what to do with the Date and the way to manage the timestamps in the mysql database. The server seems to be +2hrs and as most of my timestamps or updated on current by the database, ive been trying to convert the timestamps -2hrs.
    Only problem is im trying to get the timestamp from the database -2hrs and display it in the correct format.

    Code:
    while($lastactive_row = @mysql_fetch_array($lastactive_result))
    {
    $lastactive_username = $lastactive_row["username"];
    $lastactive_date = date("d M y H:i", strtotime($lastactive_row["last_active"]));
    just dont know the best way to do this, i thought that it was just a matter of adding -2hours before or after $lastactive_row["last_active"] but its not working.

    Any ideas?
    -2 hours are now, later could be -3 or -1 hours, that depend of server and yours settings. You must deal with local time and universal time, zonetime and day light saving, depend.
    After you solve this the code is not a problem, until then anything you do is a improvisation that could work for a short time.

    best regards

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You can also use the date_default_timezone_set() (PHP 5 >= 5.1.0) to set the default timezones used for all date/time functions.


  •  

    Posting Permissions

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