Difference of current date between PHP and Database

0

I have in my database (mysql) that I work with xampp, a Registration Façade field that is automatically fed with a CURRENT_TIMESTAMP . With PHP I consult the current date and time with the sentence date ("Y-m-d H: i: s") .

All this in order to show the time that has passed since the registration made. The problem is that date ("Y-m-d H: i: s") is giving me a date much higher than the current one, with difference in hours.

Does anyone know why this happens? or am I using wrong date ("Y-m-d H: i: s")?

    
asked by Islam Linarez 24.09.2017 в 01:47
source

1 answer

0

probably php is not using your time zone, and have another one by default. You solve this in two ways:

The first one is to put your correct time zone in the php.ini, modifying the date.timezone = your zone / time, for example mine is: date.timezone = America / Montevideo. You can see which time zone has PHP defined in the infophp.php. Or with the function date_default_timezone_get () that returns a string with the default time zone, if there is a defined one.

The second way is to tell php to temporarily use your time zone like this:

<?php
// la zona horaria por defecto en el php.ini
echo date_default_timezone_get ();
echo "<br>";
echo date('Y-m-d H:i:s');
echo "<br>";
echo "<br>";

// fijar tu zona horaria "momentaneamente"
date_default_timezone_set("America/Montevideo");
echo "America/Montevideo:";//.time();
echo "<br>";

// tu fecha y hora correctas
echo date('Y-m-d H:i:s');
?>

I hope it serves you.

    
answered by 24.09.2017 в 06:45