前面,两篇分别介绍了,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
本文转载自:https://www.gylmap.com
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
收工
年前最后一更
新年快乐!
祝各位:新的一年,恭喜发财,万事如意
来年我们一起努力!