...">
瀏覽量:134次
mysql中date函數(shù)是什么,怎么使用呢?不知道的小伙伴來看看陽泰小編今天的分享吧!
1、date函數(shù)簡介:
MySQL數(shù)據(jù)庫Date()日期函數(shù),用于MySQL數(shù)據(jù)庫查詢當前日期,時間。
2、用法:
獲取當前時間:
MySQL>?select?current_timestamp(); ?
+---------------------+ ?
|?current_timestamp()?| ?
+---------------------+ ?
|?2010-01-18?21:24:37?| ?
+---------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?current_date(); ?
+----------------+ ?
|?current_date()?| ?
+----------------+ ?
|?2010-01-18?| ?
+----------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?current_time(); ?
+----------------+ ?
|?current_time()?| ?
+----------------+ ?
|?21:24:46?| ?
+----------------+ ?
1?row?in?set?(0.00?sec) ?
Unix時間:
MySQL>?select?unix_timestamp(); ?
+------------------+ ?
|?unix_timestamp()?| ?
+------------------+ ?
|?1263821184?| ?
+------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?from_unixtime(1263821182); ?
+---------------------------+ ?
|?from_unixtime(1263821182)?| ?
+---------------------------+ ?
|?2010-01-18?21:26:22?| ?
+---------------------------+ ?
1?row?in?set?(0.00?sec) ?
時間前后:
MySQL>?select?date_add(current_timestamp,?interval?1?day); ?
+---------------------------------------------+ ?
|?date_add(current_timestamp,?interval?1?day)?| ?
+---------------------------------------------+ ?
|?2010-01-19?21:27:53?| ?
+---------------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?date_add(current_time,?interval?1?day); ?
+----------------------------------------+ ?
|?date_add(current_time,?interval?1?day)?| ?
+----------------------------------------+ ?
|?NULL?| ?
+----------------------------------------+ ?
1?row?in?set,?1?warning?(0.00?sec) ?
MySQL>?select?date_add(current_date,?interval?1?day); ?
+----------------------------------------+ ?
|?date_add(current_date,?interval?1?day)?| ?
+----------------------------------------+ ?
|?2010-01-19?| ?
+----------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?date_sub(current_timestamp,?interval?1?day); ?
+---------------------------------------------+ ?
|?date_sub(current_timestamp,?interval?1?day)?| ?
+---------------------------------------------+ ?
|?2010-01-17?21:28:41?| ?
+---------------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?date_sub(current_date,?interval?1?day); ?
+----------------------------------------+ ?
|?date_sub(current_date,?interval?1?day)?| ?
+----------------------------------------+ ?
|?2010-01-17?| ?
+----------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?date_sub(current_time,?interval?1?day); ?
+----------------------------------------+ ?
|?date_sub(current_time,?interval?1?day)?| ?
+----------------------------------------+ ?
|?NULL?| ?
+----------------------------------------+ ?
1?row?in?set,?1?warning?(0.00?sec) ?
時間間隔:
MySQL>?select?datediff('2010-01-18','2010-01-17'); ?
+-------------------------------------+ ?
|?datediff('2010-01-18','2010-01-17')?| ?
+-------------------------------------+ ?
|?1?| ?
+-------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?timediff('2010-01-18?12:00','2010-01-17?11:00'); ?
+-------------------------------------------------+ ?
|?timediff('2010-01-18?12:00','2010-01-17?11:00')?| ?
+-------------------------------------------------+ ?
|?25:00:00?| ?
+-------------------------------------------------+ ?
1?row?in?set?(0.00?sec) ?
時間轉換:
MySQL>?select?time_to_sec('25:00:00'); ?
+-------------------------+ ?
|?time_to_sec('25:00:00')?| ?
+-------------------------+ ?
|?90000?| ?
+-------------------------+ ?
1?row?in?set?(0.00?sec) ?
MySQL>?select?sec_to_time(90000); ?
+--------------------+ ?
|?sec_to_time(90000)?| ?
+--------------------+ ?
|?25:00:00?| ?
+--------------------+ ?
1?row?in?set?(0.00?sec)? ?
[聲明]本網(wǎng)轉載網(wǎng)絡媒體稿件是為了傳播更多的信息,此類稿件不代表本網(wǎng)觀點,本網(wǎng)不承擔此類稿件侵權行為的連帶責任。故此,如果您發(fā)現(xiàn)本網(wǎng)站的內(nèi)容侵犯了您的版權,請您的相關內(nèi)容發(fā)至此郵箱【779898168@qq.com】,我們在確認后,會立即刪除,保證您的版權。
官網(wǎng)優(yōu)化
整站優(yōu)化
渠道代理
400-655-5776