mysql, mysql中的date函數(shù)是什么,如何使用?不知道小伙伴們今天來看看邊肖的分享吧!
1.日期功能介紹:
MySQL數(shù)據(jù)庫Date () date函數(shù),用于查詢MySQL數(shù)據(jù)庫中的當(dāng)前日期和時間。
2.用法:
獲取當(dāng)前時間:
MySQLselectcurrent_timestamp();
+---------------------+
|current_timestamp()|
+---------------------+
|2010-01-1821:24:37|
+---------------------+
1rowinset(0.00sec)
MySQLselectcurrent_date();
+----------------+
|current_date()|
+----------------+
|2010-01-18|
+----------------+
1rowinset(0.00sec)
MySQLselectcurrent_time();
+----------------+
|current_time()|
+----------------+
|21:24:46|
+----------------+
1rowinset(0.00sec)
Unix時間:
MySQLselectunix_timestamp();
+------------------+
|unix_timestamp()|
+------------------+
|1263821184|
+------------------+
1rowinset(0.00sec)
MySQLselectfrom_unixtime(1263821182);
+---------------------------+
|from_unixtime(1263821182)|
+---------------------------+
|2010-01-1821:26:22|
+---------------------------+
1rowinset(0.00sec)
大約時間:
MySQLselectdate_add(current_timestamp,interval1day);
+---------------------------------------------+
|date_add(current_timestamp,interval1day)|
+---------------------------------------------+
|2010-01-1921:27:53|
+---------------------------------------------+
1rowinset(0.00sec)
MySQLselectdate_add(current_time,interval1day);
+----------------------------------------+
|date_add(current_time,interval1day)|
+----------------------------------------+
|NULL|
+----------------------------------------+
1rowinset,1warning(0.00sec)
MySQLselectdate_add(current_date,interval1day);
+----------------------------------------+
|date_add(current_date,interval1day)|
+----------------------------------------+
|2010-01-19|
+----------------------------------------+
1rowinset(0.00sec)
MySQLselectdate_sub(current_timestamp,interval1day);
+---------------------------------------------+
|date_sub(current_timestamp,interval1day)|
+---------------------------------------------+
|2010-01-1721:28:41|
+---------------------------------------------+
1rowinset(0.00sec)
MySQLselectdate_sub(current_date,interval1day);
+----------------------------------------+
|date_sub(current_date,interval1day)|
+----------------------------------------+
|2010-01-17|
+----------------------------------------+
1rowinset(0.00sec)
MySQLselectdate_sub(current_time,interval1day);
+----------------------------------------+
|date_sub(current_time,interval1day)|
+----------------------------------------+
|NULL|
+----------------------------------------+
1rowinset,1warning(0.00sec)
時間間隔:
MySQLselectdatediff(2010-01-18,2010-01-17);
+-------------------------------------+
|datediff(2010-01-18,2010-01-17)|
+-------------------------------------+
|1|
+-------------------------------------+
1rowinset(0.00sec)
MySQLselecttimediff(2010-01-1812:00,2010-01-1711:00);
+-------------------------------------------------+
|timediff(2010-01-1812:00,2010-01-1711:00)|
+-------------------------------------------------+
|25:00:00|
+-------------------------------------------------+
1rowinset(0.00sec)
時間轉(zhuǎn)換:
MySQLselecttime_to_sec(25:00:00);
+-------------------------+
|time_to_sec(25:00:00)|
+-------------------------+
|90000|
+-------------------------+
1rowinset(0.00sec)
MySQLselectsec_to_time(90000);
+--------------------+
|sec_to_time(90000)|
+--------------------+
|25:00:00|
+--------------------+
1rowinset(0.00sec)
mysql,以上就是本文為您收集整理的mysql最新內(nèi)容,希望能幫到您!更多相關(guān)內(nèi)容歡迎關(guān)注。