PHP - mktime store wrong date in mysql -


when store date through from_unixtime() date stores 1 day before. debug code:

$date = date("m-d-y", time());  $date_unix = explode('-', $date);  if (count($date_unix) == 3) {     list ( $m, $d, $y ) = $date_unix;     $date_unix = mktime(0, 0, 0, $m, $d, $y); }  echo "<br />date: " . $date; echo "<br />date after mktime: " . $date_unix; echo "<br />date manual mktime: " . date("m-d-y", mktime(0,0,0,8,18,2014)); 

i'm using date server, change unixtime mktime() , trying store in database from_unixtime().

$conn = new pdo(db_dsn, db_username, db_password); $sql = "insert data ( data ) values ( from_unixtime(:date_unix) )"; $st = $conn->prepare($sql); $st->bindvalue(":date_unix", $date_unix, pdo::param_int); $st->execute(); 

and after mess, mysql still stores date in day before.

ex: today 08/18/2014 , in database 2014-08-17

the date_default_timezone in server "america/cuiaba" , nothing change if change timezone.

unix timestamps utc definition. however, mysql's from_unixtime implicitly converts unix timestamp mysql server's timezone (which different setting php's default_date_timezone setting).

the america/cuiaba timezone utc - 4 hours, date "2014-08-18 00:00:00 (utc)" 2014-08-17 20:00:00 (america/cuiaba)" -- apparent 1-day difference.

have @ this answer on how convert between timezones in mysql database.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -