Convert between date and unix timestamp: Difference between revisions

Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 90: Line 90:


=== MySQL way: convert to date from unix timestamp ===
=== MySQL way: convert to date from unix timestamp ===
timezone: server timezone dependent {{exclaim}}<ref>[https://www.w3resource.com/mysql/date-and-time-functions/mysql-from_unixtime-function.php MySQL FROM_UNIXTIME() function]</ref>
timezone: MySQL server timezone dependent {{exclaim}}<ref>[https://www.w3resource.com/mysql/date-and-time-functions/mysql-from_unixtime-function.php MySQL FROM_UNIXTIME() function]</ref>


<pre>
<pre>
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 ==
Anonymous user

Navigation menu