前面,兩篇分别介紹了,MySQL的字符串函數和數值函數,接下來,一起學習下日期函數,走起[奸笑]
上圖
1.NOW()獲取當前時間
SQL語句:SELECT NOW() as temporary_time
2.YEAR()獲取當前年份
SQL語句:SELECT YEAR(NOW()) as temporary_time
3.MONTH()獲取當前月份
SQL語句:SELECT MONTH(NOW()) as temporary_time
4.WEEK()獲取當前是今年的第幾周
SQL語句:SELECT WEEK(NOW()) as temporary_time
5.DAY()獲取本月幾号
SQL語句:SELECT DAY(NOW()) as temporary_time
6.HOUR()獲取當前小時
SQL語句:SELECT HOUR(NOW()) as temporary_time
7.MINUTE()獲取當前分鐘
SQL語句:SELECT MINUTE(NOW()) as temporary_time
8.MONTHNAME()返回英文月份
SQL語句:SELECT MONTHNAME(NOW()) as temporary_time
9.CURDATE()返回當前日期,隻包含年月日
SQL語句:SELECT CURDATE() as temporary_time
10.CURTIME() 返回當前時間,隻包含時分秒
SQL語句:SELECT CURTIME() as temporary_time
11.UNIX_TIMESTAMP()返回時間戳
SQL語句:SELECT UNIX_TIMESTAMP(NOW()) as temporary_time
12.FROM_UNIXTIME()返回對應時間戳的日期值
SQL語句:SELECT FROM_UNIXTIME(1612166213) as temporary_time
13.DATE_FORMAT(date,format)格式化 日期函數
SQL語句:SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') as temporary_time
14. DATEDIFF(x,y) 計算日期相差多少天,y-x
SQL語句:SELECT DATEDIFF('1995-11-06','1994-09-22') as temporary_time
收工[鼓掌]
年前最後一更[奸笑]
新年快樂!
祝各位:新的一年,恭喜發财,萬事如意[撒花]
來年我們一起努力!
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!