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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:52:22+00:00 2026-06-13T22:52:22+00:00

I want to convert the date I fetched from the database, which is generated

  • 0

I want to convert the date I fetched from the database, which is generated via CURRENT_TIMESTAMP and stored in a timestamp column type, from GMT+8 to GMT+1.

$time = "2012-11-07 15:05:26"; // fetch from database
$date = new DateTime($time, new DateTimeZone('Europe/Berlin'));
echo $date->format('Y-m-d H:i:s');

However this will yield an output of “2012-11-07 15:05:26”, which I’m pretty sure is wrong.

What could be I’m missing in here?

  • 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-13T22:52:23+00:00Added an answer on June 13, 2026 at 10:52 pm

    First, you need to instantiate the datetime object with the original timezone. Then, after the datetime object is instantiated, adjust the timezone with DateTime::setTimezone().

    See this code, where I’ve used Asia/Hong_Kong as an example GMT+8 timezone:

    $time = "2012-11-07 15:05:26"; // fetch from database
    $date = new DateTime($time,new DateTimeZone('Asia/Hong_Kong'));
    $date->setTimezone(new DateTimeZone('Europe/Berlin'));
    echo $date->format('Y-m-d H:i:s'); // yields 2012-11-07 08:05:26
    

    If all the original dates are always consistently meant as GMT+8, and your PHP application is set to use GMT+8 as well (set with date_default_timezone_set(), for instance), there’s no need to pass the initial DateTimeZone object, as newly created DateTime objects will automatically be created with that timezone.

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

Sidebar

Related Questions

I want to convert the following date: 2010-02-01T13:58:58.513Z Which is stored in a NSString
I want to convert the timestamp object(fetched from models) according to given UTC offset
I want to convert string Date into Timestamp in java. The following coding i
I want to convert date of birth from a text file.Let's say, I have
I have a timestamp I want to convert to a date. I tried this
I am geting below date from the server now I want to convert string
I want to convert date format from 01/09 to January 2009 , 09/03 to
I want to convert date from MM/YYYY to MM/DD/YYYY, how i can do this
I want to convert date from one format to another.Let's say, I have some
I want to convert my date (which is in String format), e.g. 13-09-2011, into

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.