1. MySQL Gets the current timestamp function: Current_timestamp, Current_timestamp ()
Mysql> Select Current_timestamp, Current_timestamp ();
+---------------------+---------------------+
| Current_timestamp | Current_timestamp () |
+---------------------+---------------------+
| 2008-08-09 23:22:24 | 2008-08-09 23:22:24 |
+---------------------+---------------------+
2. MySQL (Unix timestamp, date) conversion function:
Unix_timestamp (),
Unix_timestamp (date),
From_unixtime (Unix_timestamp),
From_unixtime (Unix_timestamp,format)
Here's an example:
Select Unix_timestamp (); --1218290027
Select Unix_timestamp (' 2008-08-08 '); --1218124800
Select Unix_timestamp (' 2008-08-08 12:30:00 '); --1218169800
Select From_unixtime (1218290027); --' 2008-08-09 21:53:47 '
Select From_unixtime (1218124800); --' 2008-08-08 00:00:00 '
Select From_unixtime (1218169800); --' 2008-08-08 12:30:00 '
Select From_unixtime (1218169800, '%Y%d%M%h:%i:%s%x '); --' 8th August 12:30:00 2008 '
3. MySQL timestamp (timestamp) conversion, increment, decrement function:
Timestamp (date)--date to timestamp
Timestamp (dt,time)--DT + Time
Timestampadd (unit,interval,datetime_expr)--
Timestampdiff (UNIT,DATETIME_EXPR1,DATETIME_EXPR2)--
Take a look at the Example section:
Select timestamp (' 2008-08-08 '); --2008-08-08 00:00:00
Select Timestamp (' 2008-08-08 08:00:00 ', ' 01:01:01 '); --2008-08-08 09:01:01
Select Timestamp (' 2008-08-08 08:00:00 ', ' 10 01:01:01 '); --2008-08-18 09:01:01
Select Timestampadd (Day, 1, ' 2008-08-08 08:00:00 '); --2008-08-09 08:00:00
Select Date_add (' 2008-08-08 08:00:00 ', Interval 1 day); --2008-08-09 08:00:00
The MySQL Timestampadd () function is similar to Date_add ().
Select Timestampdiff (year, ' 2002-05-01 ', ' 2001-01-01 '); ---1
Select Timestampdiff (Day, ' 2002-05-01 ', ' 2001-01-01 '); ---485
Select Timestampdiff (Hour, ' 2008-08-08 12:00:00 ', ' 2008-08-08 00:00:00 '); ---12
Select DateDiff (' 2008-08-08 12:00:00 ', ' 2008-08-01 00:00:00 '); --7
The MySQL Timestampdiff () function is much stronger than the DateDiff () function, and DateDiff () can only calculate the number of days between two dates (date).
MySQL time stamp