content_image/744105.jpg
-> 1447431666 mysql> SELECT UNIX_TIMESTAMP(’2015-11-13 10:20:19’); -> 1447431619 mysql> SELECT UNIX_TIMESTAMP(’2015-11-13 10:20:19.012’); -> 1447431619.012 

If you use UNIX_TIMESTAMP()  and FROM_UNIXTIME()  to convert between values in a non-UTC time zone and Unix timestamp values, the conversion is lossy because the mapping is not one-to-one in both directions. For example, due to conventions for local time zone changes such as Daylight Saving Time (DST), it is possible for UNIX_TIMESTAMP()  to map two values that are distinct in a non-UTC time zone to the same Unix timestamp value. FROM_UNIXTIME()  maps that value back to only one of the original values. Here is an example, using values that are distinct in the MET  time zone: 

mysql> SET time_zone = ’MET’; mysql> SELECT UNIX_TIMESTAMP(’2005-03-27 03:00:00’); +---------------------------------------+ | UNIX_TIMESTAMP(’2005-03-27 03:00:00’) | +---------------------------------------+ | 1111885200 | +---------------------------------------+ mysql> SELECT UNIX_TIMESTAMP(’2005-03-27 02:00:00’); +---------------------------------------+ | UNIX_TIMESTAMP(’2005-03-27 02:00:00’) | +---------------------------------------+ | 1111885200 | +---------------------------------------+ mysql> SELECT FROM_UNIXTIME(1111885200); +---------------------------+ | FROM_UNIXTIME(1111885200) | +---------------------------+ | 2005-03-27 03:00:00 | +---------------------------+ 

<img src='content_image/744105.jpg'>

## Note 

To use named time zones such as ’MET’  or ’Europe/Amsterdam’ , the time zone tables must be properly set up. For instructions, see Section 5.1.15, “MySQL Server Time Zone Support” . 

If you want to subtract UNIX_TIMESTAMP()  columns, you might want to cast them to signed integers. See Section 12.11, “Cast Functions and Operators” . 

• UTC_DATE , UTC_DATE() 

Returns the current UTC date as a value in ’ YYYY-MM-DD ’  or YYYYMMDD  format, depending on whether the function is used in string or numeric context. 

mysql> SELECT UTC_DATE(), UTC_DATE() + 0; -> ’2003-08-14’, 20030814 

• UTC_TIME , UTC_TIME([ fsp ]) 

Returns the current UTC time as a value in ’hh:mm:ss’  or hhmmss  format, depending on whether the function is used in string or numeric context. 

If the fsp  argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits. 

mysql> SELECT UTC_TIME(), UTC_TIME() + 0; -> ’18:07:53’, 180753.000000 

