Convert between date and unix timestamp: Difference between revisions
Jump to navigation
Jump to search
→Convert between date and unix timestamp
| Line 95: | Line 95: | ||
SELECT FROM_UNIXTIME(IF(`timestamp_column` = 0, NULL, `timestamp_column`, "%Y-%m-%d %H:%i:%S") | SELECT FROM_UNIXTIME(IF(`timestamp_column` = 0, NULL, `timestamp_column`, "%Y-%m-%d %H:%i:%S") | ||
</pre> | </pre> | ||
=== MySQL way: convert to unix timestamp from date time === | |||
Using [https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_unix-timestamp UNIX_TIMESTAMP()] function | |||
timezone: MySQL server timezone dependent {{exclaim}} | |||
* {{kbd | key = SELECT UNIX_TIMESTAMP('2011-03-15 18:53:57');}} /* return timestamp: 1300186437 */ | |||
* {{kbd | key = SELECT UNIX_TIMESTAMP(STR_TO_DATE('2011-03-15 18:53:57', '%Y-%m-%d %H:%i:%S'));}} /* return timestamp: 1300186437 */ | |||
== References == | == References == | ||