+ Reply to Thread
Results 1 to 5 of 5

Thread: DateTime in PHP

  1. #1
    Randy Shaffer is offline New Bee
    Join Date
    Oct 2007
    Location
    Pensacola Beach, Florida
    Posts
    5
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DateTime in PHP

    I am just learning PHP. I have a simple program to display the time. Why is the server time 6 hours ahead of central time? I thought all the serves were in Delaware?

    http://www.nevb.us/SQL-PHP/dateSelect-vb.php

    $today = time(); //stores today's date
    $f_today = date("M-d-Y",$today); //formats today's date
    $f_time = date("h-i-s-a",$today); //formats today's time

    Thanks,
    Randy

  2. #2
    Randy Shaffer is offline New Bee
    Join Date
    Oct 2007
    Location
    Pensacola Beach, Florida
    Posts
    5
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Gmt

    I would bet it always returns Greenwich Mean Time (GMT).

  3. #3
    Saf M Guest

    Default

    I would bet it always returns Greenwich Mean Time (GMT).
    Our servers are located at three different locations.

    1. Dallas
    2. Atlanta
    3. New Jersey

    We also have lots of clients from other parts of the world. Therefore to keep things simple and organized we have set the time to GMT by default on all servers.

    You can always display your local time on your website as this should not have direct relationship with it unless your script is programmed to fetch this data from the server clock.
    Last edited by Saf M; 02-08-2008 at 12:52 PM.

  4. #4
    PsyCHZZZ's Avatar
    PsyCHZZZ is offline aspiring dreamer~
    Join Date
    Dec 2006
    Location
    Tokyo, Japan.
    Posts
    142
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Randy,

    As you would already know, the time() function retrieves the current time from the server. Now since you know that the server time is always x hours ahead; one easy way is to just add to the time() function like this:
    //Assuming that time is 6 hours ahead from the server time
    $today = time()+(6*60*60); //stores today's date and add additional 6 hours
    $f_today = date("M-d-Y",$today); //formats today's date
    $f_time = date("h-i-s-a",$today); //formats today's time
    ** NOTE: This will always display "your" local time so different visitors from different parts of the world would not have the time sync with theirs. If you need to display the visitors local time always; you'll need to use Javascript and fetch the data from the client's machine and not from the server.

    Hope this helps. Cheers~
    Last edited by PsyCHZZZ; 02-10-2008 at 12:09 PM. Reason: Added additional footnotes.

  5. #5
    Randy Shaffer is offline New Bee
    Join Date
    Oct 2007
    Location
    Pensacola Beach, Florida
    Posts
    5
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Saf M and PsyCHZZZ. I add the 6 hours in the formula, but then thought that day light savings time would change it to 5 hours and I would have to change the code. I found this code - putenv("TZ=US/Eastern"); and inserted it after $today = time(); It seems to work. We will see when we spring forward.

+ Reply to Thread

Posting Permissions

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