Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3853412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:27:54+00:00 2026-05-19T17:27:54+00:00

I allow my users to add events to my webapp. Users can originate from

  • 0

I allow my users to add events to my webapp. Users can originate from all around the world.

My current idea is to determine the user’s time zone automatically (using an IP to location API) and insert it into the users table (I will also allow them to change it).

On the events table I will insert the event start date/end date in UTC.

Then, whenever I need to display the event info, I would take the event start date/end date from the table and do the calculation against the user’s timezone.

Is that considered as good practice or is there a better way to do that?

Anything I should be aware of when doing this?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:27:55+00:00Added an answer on May 19, 2026 at 5:27 pm

    Yes, that is indeed a good way. Also keep in mind that if you use the TIMESTAMP type in MySQL, MySQL handles the timezone converting for you. When you insert new dates/times to the database, MySQL converts it from the connection’s timezone to UTC (TIMESTAMP is always stored in UTC). When you retrieve a TIMESTAMP field from database, MySQL converts it back to the connection’s timezone.

    So if you use TIMESTAMP fields in MySQL, all you need to do is tell the user’s timezone to MySQL at start of each your page. You do so by:

    SET time_zone = 'Europe/Helsinki'
    

    You can also use numeric timezones:

    SET time_zone = '+02:00'
    

    Keep in mind that you might need to install the tzinfo to MySQL first, which is trivial though (only for the non-numeric version though). Here’s information about how to do it: http://dev.mysql.com/doc/refman/5.0/en/mysql-tzinfo-to-sql.html

    In a nutshell, this is the important part:

    mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
    

    Here’s an example of how it works:

    mysql> CREATE TEMPORARY TABLE test(foo TIMESTAMP);
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SET time_zone = '+00:00';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> INSERT INTO test VALUES ('2011-02-03 16:00:00');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> SET time_zone = '+02:00';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SELECT foo FROM test;
    +---------------------+
    | foo                 |
    +---------------------+
    | 2011-02-03 18:00:00 |
    +---------------------+
    1 row in set (0.00 sec)
    

    If you don’t use TIMESTAMP field, eg. you use DATETIME (which also supports wider range of dates), then you just need to make sure you always insert dates in UTC; I do this by always setting connection’s timezone to +00:00. Then you can have a view helper in PHP that converts the datetime to the user’s timezone, which is quite trivial to do with PHP’s DateTime class and setTimezone function. There’s an example in the last link. To use this method, you must make sure PHP is also set to use UTC as its default timezone, which you can do with this:

    date_default_timezone_set('UTC');
    

    Whichever method you use, you should always be aware of these facts:

    • The PHP and MySQL connection’s timezones should always be set to the same value so they’re consistent with each other
    • Generally it’s a bad idea to mix TIMESTAMP and DATETIME types with each other
    • If you use TIMESTAMP type, set the timezone to the user’s timezone
    • If you use DATETIME type, set the timezone to UTC and handle timezone convertions in PHP
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an app where I allow the user to add events to a
I want to allow users of my application to add sub-users and set privileges
To allow users and site admins to view/add/edit/delete data in my application I decided
I am trying to add a simple form to allow my users to edit
Is it possible to allow a user to add and edit column names for
I am writing a PHP application that's supposed to allow users to add certain
I am using CKeditor to allow users to add images to their textboxes in
There is a one section of orders page where users can add new fields
I am trying to allow users to drag a page from a PDF pages
I have a Drupal site where I want to allow users to add their

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.