mysql中的日期函数用法(MySQL常用函数之日期函数)
前面,两篇分别介绍了,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
收工[鼓掌]
年前最后一更[奸笑]
新年快乐!
祝各位:新的一年,恭喜发财,万事如意[撒花]
来年我们一起努力!
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com