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

  • Home
  • SEARCH
  • 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 6656575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:39:37+00:00 2026-05-26T01:39:37+00:00

Possible Duplicate: Datatype/structure to store timezones in MySQL I’ll be storing only UTC times

  • 0

Possible Duplicate:
Datatype/structure to store timezones in MySQL

I’ll be storing only UTC times in my database, and want to convert the timestamps to a user’s local time using PHP.

My question is, what is the best way to store the users timezone in the database?

IE: -400, -4, -4:00

With that said, I know how to do the math manually:

$utc_time = strtotime("2011-10-02 23:00:00");
$my_time = $utc_time - 14400;

echo date($timeformat, $mytime);

My problem is, with the user’s timezone being pulled from the database, I don’t know whether I’ll be adding or subtracting seconds. That’s where I run into the problem of trying to figure out how to save the timezone so that I can calculate the offset.

I can save the timezone as “-14400”, but using the above example, I can’t just combine the two strings to do the math for me using the – sign:

$my_time = $utc_time.$timezone;

So… how do I save the timezone properly to get the math done?

  • 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-26T01:39:38+00:00Added an answer on May 26, 2026 at 1:39 am

    The timezone in one location isn’t always the same – for example, the UK is BST (GMT + 1) between March and October. Use one of the timezones supported by PHP:

    http://php.net/manual/en/timezones.php

    If you do go ahead using numbers, either store them as hours or minutes. Store timezones west of UTC/GMT as negative numbers. For example, the US East Coast would be -5 (hours) or -300 (minutes) – assuming it’s 5 hours behind.

    Then, add this to the timestamp – the negative or positive will handle the rest.

    // for 5 hours behind when stored as hours (-5)
    $now = time() + ($offset * 60 * 60);
    // for 5 hours behind when stored as minutes (-300)
    $now = time() + ($offset * 60);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Which MySQL Datatype to use for storing boolean values? I am a
Possible Duplicate: How to store an IP in mySQL I want to get the
Possible Duplicate: What type should I store IP addresses for MySQL? One single datatype
Possible Duplicate: What structure type do I use for HTML content (MySQL) What's the
Possible Duplicate: Storing primitive values in a Java collection? ArrayList accepts only reference types
Possible Duplicate: mysql datatype for telephne number and address Any suggestions on best practice
Possible Duplicate: size of a datatype in c I want to ask you does
Possible Duplicate: Does SQL Server 2005 have an equivalent to MySql’s ENUM data type?
Possible Duplicate: Add 1 hour to datetime datatype I have a timestamp stored in
Possible Duplicate: How do you set a default value for a MySQL Datetime column?

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.