Results 1 to 3 of 3

Thread: Dealing with times and time zones for timestamping comments (and other things)

  1. #1
    Join Date
    Jul 2010
    Thanked 0 Times in 0 Posts

    Default Dealing with times and time zones for timestamping comments (and other things)

    This is my first post so please forgive me if I break any rules unwittingly.

    I want to add date and time to comments on a PHP database driven page.

    I want the times to be local (relative to the person using the page) but I don't want the time itself to be derived from the computer of the person using the page. The reason for that is I don't want to record an incorrect time if their computer time happens to be wrong (not likely these days but possible)

    I know I can get the mysql time using the now() function. I also know I can add or subtract hours from it to get the time in a different time zone. But for that I'd have to pick a time zone and stick to it.

    If getting the accurate time of the place where the page is being viewed is a messy process then I'd be ok with using a specific time (in my case GMT or BST)

    Basically I am asking what is the accepted way of dealing with the time and date for page comments.

  2. #2
    Join Date
    Apr 2008
    Thanked 516 Times in 502 Posts
    Blog Entries


    you could have javascript return the user's time to your server and try to figure it out from there, or use something like this to find out where their IP is and figure out the time zone from there, but neither method is particularly certain. They could easily be faked, or even just wrong.

    Most forums (this one, for example) simply ask the user what time zone they're in during registration (or via the CP).

  3. #3
    Join Date
    Mar 2006
    Illinois, USA
    Thanked 690 Times in 678 Posts


    There's no real reason not to guess as long as you also make it possible to choose later. GeoIP by Max Mind (available as a free light version and full paid version) is a good tool to get some idea where the user is. If they are faking it, then I doubt they'll mind that you guessed wrong, and if you are wrong sometimes it won't hurt much as long as you allow the user to choose: there's no reason to assume that a default would be closer to the user than the wrong guess.
    Also, IP location services are somewhat inaccurate, but just determining what timezone someone is in should not be very difficult: it is a 1/24 chance and the services are generally accurate at least to within the right country. (Most of the time...)

    One problem to remember is daylight savings time. Some countries (or even parts of countries, like Arizona, USA) don't do daylight savings time, while many others do. This means that the best guess is by country (or smaller region!), so there may be a big difference between, for example, New York, USA and Brazil. Hopefully the IP location software will be at least close. And at the very least it will probably be only a few hours wrong (or probably one hour wrong if it's due to daylight savings time)...
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum


Posting Permissions

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