How to convert timestamp to general time format in MYSQL
This article is about how to convert the timestamp into a general time format in MYSQL. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
How to convert MYSQL timestamps to general time format
UNIX_TIMESTAMP (date)
If there is no argument call, returns a Unix timestamp (seconds from '1970-01-01 00:00:00'GMT). If UNIX_TIMESTAMP () is called with a date parameter, it returns the second value from' 1970-01-01 00:00:00'GMT. Date can be a DATE string, a DATETIME string, a TIMESTAMP, or a number of local time in YYMMDD or YYYYMMDD format. Www.2cto.com
> select UNIX_TIMESTAMP ()
-> 882226357
Mysql > select UNIX_TIMESTAMP ('1997-10-04 22 purge 23purl 00')
-> 875996580
When UNIX_TIMESTAMP is used for a TIMESTAMP column, the function accepts the value directly, with no implicit "string-to-unix-timestamp" transformation.
Www.2cto.com
FROM_UNIXTIME (unix_timestamp)
Returns the value represented by the unix_timestamp parameter in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.
Mysql > select FROM_UNIXTIME (875996580)
-> '1997-10-04 22 22 purl 2300'
Mysql > select FROM_UNIXTIME (875996580) + 0
-> 19971004222300
FROM_UNIXTIME (unix_timestamp,format)
Returns a string representing the Unix time stamp, formatted according to the format string. Format can contain the same modifiers as the entries listed in the DATE_FORMAT () function.
Mysql > select FROM_UNIXTIME (UNIX_TIMESTAMP ()
'y D M h:%i:%s x')
-> '1997 23rd December 03:43:30 x'
The above is how to convert the timestamp into a general time format in MYSQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.