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
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 ', ' 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 ');---
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).