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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:49:42+00:00 2026-06-08T17:49:42+00:00

I have a PHP MySQL query that inserts some data into a MySQL database

  • 0

I have a PHP MySQL query that inserts some data into a MySQL database and it includes a timestamp.

Currently the INSERT query uses NOW() for the the timestamp column and it is saved in the database in the following format: 2012-07-24 13:13:02

Unfortunately for me the Server is not in my time zone and it is listed as America/Los_Angeles as shown print date_default_timezone_get();

I was hoping to do the following:

date_default_timezone_set('Europe/London');
$timefordbLondonEU = date('Y-m-d H:i:s', time());

and simply save into the database the $timefordbLondonEU in place of the NOW();

Is this a good way to save such data ?

Many Thanks,

Richard

[ADDED TEXT]

I changed the Type in the MySQL db to DateTime and did the following:

date_default_timezone_set('Europe/London');
$timefordbLondonEU = date('Y-m-d H:i:s', time()); 

It is working but Im still not getting the overall concept yet.

Assumptions based on your comments:
  1. MySQL = Does not have a datatype UTC you simply use type INT.
  2. Unix_TimeStamp() will save the current time or count? in UTC format such as 1343247227.
  3. As UTC is a count from a common 0 point you can get any timezone from it. Assuming that you don’t want a date before the reference 0 point in 1970.

My guess and lead on from what you have said is the best way to do it is save the time as UTC in an INT (1343247227) and then generate any time zones you want from there. Again assuming you don’t need to store dates before the reference 0 point in 1970.

Equally why not store as datetime YYYY-MM-DD HH:MM:SS at a known timezone and then convert to UTC or other timezones. It all seems pretty messy =(

  • 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-06-08T17:49:43+00:00Added an answer on June 8, 2026 at 5:49 pm

    As @Petah said in the comments, store your times in UTC and covert them in the application as needed.

    Unix timestamps are in UTC so I usually store my times in the database as timestamps. This saves the headache and confusion of first converting to UTC to insert, and then from UTC when selecting.

    That is, make your time field an INT type, and use the function UNIX_TIMESTAMP() in MySQL when you insert, or get the timestamp from PHP using the time() function.

    When you fetch the timestamp from the DB it will be in UTC, but when you display it in your PHP application using date(), it will display in the server timezone, or whatever you set with date_default_timezone_set.

    Therefore the following two queries will work:

    INSERT INTO `table` (id, time) VALUES(NULL, UNIX_TIMESTAMP());
    
    // or
    
    $time = time();
    
    $query = "INSERT INTO `table` (id, time) VALUES(NULL, $time);
    

    If you want to select it from the DB as a DATETIME, you can do this:

    SELECT *, FROM_UNIXTIME(time) as dt FROM `table` WHERE 1
    

    The resulting dt column will be in the format yyyy-MM-dd hh:mm:ss.

    You can format the numeric timestamp in PHP using date()

    If the PHP version you have is 64-bit, you aren’t limited to the 1970 – 2036 range, PHP will support 64-bit timestamps, just make sure to use a BIGINT column in MySQL in that case.

    Hope that helps.

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

Sidebar

Related Questions

I have a PHP script that inserts data into a mysql database. The table
I have a form that uses ajax to submit data to a mysql database,
I have a PHP/MySQL query that returns to an HTML table, and I'm stuck
Let's say that I have an error in a php/mysql query : $query =
I have a php script that runs a mysql query, then loops the result,
Right now I have a PHP file that does a MYSQL query and then
I have a simple query (in a mySQL view) that php is using to
So I'm trying to import some sales data into my MySQL database. The data
Here's the thing, I don't have access to code that inserts data into a
I'm creating a PHP script that imports some data from text files into a

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.