1

Column date is timestamp - default - current_timestamp

example value: 2017-04-07 09:45:53

$stmt = $db->query("select * from cinema order by date desc");
    while($row = $stmt->fetch()){
        $date = strtotime($row['date']);
        $datea = date("d-m-y", $date);
        $time = date("H:i", $date);

I'm getting -2 hours difference comparing to my timezone - 09:45 instead of 11:45 - so I tried:

$stmt = $db->query("SELECT *, CONVERT_TZ(date, '+00:00', '+01:00') FROM cinema order by date desc"); - without success

I also tried to change column type from timestamp (current_timestamp) to datetime (current_timestamp).

And still getting -2 hours difference.

Any help?

qadenza
  • 9,025
  • 18
  • 73
  • 126

1 Answers1

1

You can try something like:

$stmt = $db->query("SELECT *, CONVERT_TZ(date, @@session.time_zone, '+02:00') AS mydate FROM cinema order by mydate desc");

Here are some reading that might be helpful when working with date and time: https://stackoverflow.com/a/19075291/1363190

Community
  • 1
  • 1
Michael Krikorev
  • 2,126
  • 1
  • 18
  • 25