MySQL writes "as-is" dates, also reads them like this, but UNIX_TIMESTAMP processes any input dates, as in your local time zone, and converts them to UTC / GMT time stamps, which means that it will apply your local time zone offset, now, timestamps returned from mysql, for example. php date () it will apply your local timezone offset again (note that there is also gmtime () which does not), which will lead to undesirable results.
But you can go through with the following trick that subtracts the session time zone before UNIX_TIMESTAMP () applies it, so you will get the exact number regardless of the server / local time zone if you want the exact same date in db as if itโs GMT.
mysql> SELECT UNIX_TIMESTAMP(CONVERT_TZ("2013-05-27","GMT",@@session.time_zone)); +--------------------------------------------------------------------+ | UNIX_TIMESTAMP(CONVERT_TZ("2013-05-27","GMT",@@session.time_zone)) | +--------------------------------------------------------------------+ | 1369612800 | +--------------------------------------------------------------------+ 1 row in set (0.00 sec)
Another solution would be to set the servers or the time zone of the session to 0 (GMT), so there will be no real conversions.
source share