Search code examples
phpmysqltimeunix-timestamp

PHP - Want to convert MySQL Timestamp time to UTC +6 time


I have an old MySQL database. Here is a time column. I see here is some time values Like:

2013-06-03 21:33:15

So, I want to convert this time to my local time UTC +6 in my PHP Script. How can it possible? I can make a mysql query to get the time from Database to my my PHP variable $TimeFromMySQL Just now I want to show like:

11:32:44 PM 05 July 2014

Thank You


Solution

  • See VMai's comment above if you want to do this in MySQL. For PHP:

    $inDate = '2013-06-03 21:33:15';
    $inDate_tz = 'America/Chicago';
    
    $original_date = new DateTime($inDate, new DateTimeZone($inDate_tz) );
    $original_date->setTimeZone(new DateTimeZone('Asia/Dhaka'));
    $new_date =  $original_date->format('H:i:s d F Y');
    
    echo $new_date;
    
    //outputs 08:33:15 04 June 2013