简体   繁体   中英

Different PHP and MySQL date time

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

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?

In MySQL :

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".)

In PHP :

<?php
echo date_default_timezone_get();
// Europe/Madrid

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM