Reputation: 174
I am facing an issue regarding date time returned by PHP and MySQL . I checked PHP date, using
echo date("Y-m-d h:m:s");
It returned
2013-07-31 01:07:37
then i executed a query in mysql console(phpmyadmin/sqlyog) with query
SELECT NOW() as date_time
it resulted
2013-07-31 15:40:36
Firslty I want that both should result dame date time, secondly how can i set any one of them to match the other one.
Note: I checked that on local and live server both
Upvotes: 0
Views: 913
Reputation: 146573
Apart from the typo in the format codes, it seems that MySQL and PHP are not configured to use the same time zone. How to find out?
mysql> SELECT @@session.time_zone;
+---------------------+
| @@session.time_zone |
+---------------------+
| SYSTEM |
+---------------------+
1 row in set (0.00 sec)
(In this example, SYSTEM
means "the time zone of the host machine".)
<?php
echo date_default_timezone_get();
// Europe/Madrid
Upvotes: 6
Reputation: 33563
Your date
format string is wrong. It should read
date ("Y-m-d H:i:s");
In the documentation it says h
is hours in 12-hour format and m
is month, not minutes. The difference in two hours can be explained by timezone (and / or DST).
Upvotes: 2