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 6383155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:36:49+00:00 2026-05-25T02:36:49+00:00

How should I go about dealing with timezone. Is it safe to just store

  • 0

How should I go about dealing with timezone. Is it safe to just store the offset for the user? Or should I also have the Area/Location? When I compared the offset values in Wikipedia and PHP, some doesn’t match. Which should I trust?

Lastly how should I go about with it in PHP. Can I just do a “Time – Server Offset + User Offset”?

  • 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-25T02:36:49+00:00Added an answer on May 25, 2026 at 2:36 am

    Area and location is important if you care about retaining all the data. The best way (in my opinion) to store dates is to store a UTC timestamp + the location.

    Just the offset may be enough for certain calculations, but it could not be enough if you have a timestamp, and want to know the exact time for something like “+1 day”. As this varies in different countries with different rules for daylight savings time.

    So if you want to be absolutely certain you are not ‘losing information’ and unable to do time-based calculations in the future, store the UTC timestamp and the olson id (e.g.: Europe/Amsterdam).

    To answer your second question, if you have these two pieces of information, you can easily reconstruct it with DateTime:

    $dt = new DateTime('@' . $timeStamp);
    // Now convert it to the users timezone
    $dt->setTimeZone(new DateTimeZone('Europe/Berlin'));
    
    // Now you have a 'DateTime' object which you can easily display with the ->format function.
    

    Addition

    I personally prefer to store timestamps as integers. The TIMESTAMP type does automatic conversion, and I feel it’s better to let the PHP application handle this, this makes especially sense for what I think your use-case is (simple localization for users).

    Using DATETIME works too, but the storage requirements are much higher than just using an integer. If you do prefer DATETIME, try to make it a rule within your application to store every value always as UTC, as there is never any confusion especially in relation to DST transitions and law changes in your local timezone.

    If you simply want to show times on your web application calculated based on the users’ local timezone, the offset is useless. The offset changes twice a year for most countries, and almost every year one or two country changes when this happens.

    You only need the location if you use PHP’s awesome DateTime and DateTimeZone objects.

    A last bit of advice:

    People tend to confuse dates and times in PHP applications and sending around these values in many different formats (strings, ints, etc) and mix GMT and UTC. Try to make it a rule for yourself to only ever send around DateTime objects in function arguments and return values, so you can typehint and there is never any doubt in what format a variable is in. It will be worth it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when dealing with mongodb, when should i use the {safe: true} on queries? Right
The problem I have today is about dealing with HTML in an included JSP,
I have a question about how should I handle image files of various sizes
We should forget about small efficiencies, say about 97% of the time: premature optimization
Are there any VC++ settings I should know about to generate better PDB files
Are there any big differences a developer should care about?
Are there any open-source libraries that all programmers should know about? I'm thinking something
I'm wondering that how much worried I should be about data types. I can
As Knuth said, We should forget about small efficiencies, say about 97% of the
What are all the common undefined behaviours that a C++ programmer should know about?

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.