MySQL日期的相關(guān)函數(shù)介紹
數(shù)據(jù)庫(kù)中日期和時(shí)間都是很重要的,下面就為您介紹幾個(gè)和MySQL日期時(shí)間相關(guān)的函數(shù),供您參考,希望對(duì)您學(xué)習(xí)MySQL日期時(shí)間方面有所幫助。
獲得當(dāng)前日期(date)函數(shù):curdate()
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2008-08-08 |
+------------+
其中,下面的兩個(gè)日期函數(shù)等同于 curdate():
current_date()
,current_date
獲得當(dāng)前時(shí)間(time)函數(shù):curtime()
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 22:41:30 |
+-----------+
其中,下面的兩個(gè)時(shí)間函數(shù)等同于 curtime():
current_time()
,current_time
獲得當(dāng)前 UTC 日期時(shí)間函數(shù):utc_date(), utc_time(), utc_timestamp()
mysql> select utc_timestamp(), utc_date(), utc_time(), now()
+---------------------+------------+------------+---------------------+
| utc_timestamp() | utc_date() | utc_time() | now() |
+---------------------+------------+------------+---------------------+
| 2008-08-08 14:47:11 | 2008-08-08 | 14:47:11 | 2008-08-08 22:47:11 |
+---------------------+------------+------------+---------------------+
因?yàn)槲覈?guó)位于東八時(shí)區(qū),所以本地時(shí)間 = UTC 時(shí)間 + 8 小時(shí)。UTC 時(shí)間在業(yè)務(wù)涉及多個(gè)國(guó)家和地區(qū)的時(shí)候,非常有用。
以上就是MySQL日期的相關(guān)函數(shù)介紹。
【編輯推薦】