0

Here I select a date: 21 Feb, 2019

$ri_arrival_date = $_POST["ri_arrival_date"];
$arvl_date = strtotime($ri_arrival_date);
$arvl_date = date('d M,Y',$arvl_date);
$check_in_date = $ri_arrival_date;
$datetime = new DateTime($arvl_date);
$datetime->setTime(0, 0, 0);
$arvl_date = $datetime->getTimestamp();
echo $arvl_date;

echo result is 1550703600 (February 21, 2019 5:00:00 AM) But in my database it saved by 1550685600 (February 21, 2019 12:00:00 AM) Two value is different.

I want to get 1550685600 the database DateTime value. But it couldn't match.

2 Answers2

0

I just use $datetime->setTime(-5, 0, 0); to fix this problem.

0

Verify the server timezone and the mysql timezone if is on a different server.

In all my php I set my timezone based on my location defined instead of the one of the server. This will eliminate the confusion If host my server on another timezone. And also can be expanded/upgrade to accept the user timezone if needed.

<?php

date_default_timezone_set('America/New_York');

?>
Vidal
  • 2,605
  • 2
  • 16
  • 32