MySQL日期的相關函數介紹
數據庫中日期和時間都是很重要的,下面就為您介紹幾個和MySQL日期時間相關的函數,供您參考,希望對您學習MySQL日期時間方面有所幫助。
獲得當前日期(date)函數:curdate()
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2008-08-08 |
+------------+
其中,下面的兩個日期函數等同于 curdate():
current_date()
,current_date
獲得當前時間(time)函數:curtime()
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 22:41:30 |
+-----------+
其中,下面的兩個時間函數等同于 curtime():
current_time()
,current_time
獲得當前 UTC 日期時間函數: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 |
+---------------------+------------+------------+---------------------+
因為我國位于東八時區,所以本地時間 = UTC 時間 + 8 小時。UTC 時間在業務涉及多個國家和地區的時候,非常有用。
以上就是MySQL日期的相關函數介紹。
【編輯推薦】