搜索
写经验 领红包
 > 房产

mysql中的日期函数(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(),&39;) as temporary_time

14. DATEDIFF(x,y) 计算日期相差多少天,y-x

SQL语句:SELECT DATEDIFF(&39;,&39;) as temporary_time

收工[鼓掌]

年前最后一更[奸笑]

新年快乐!

祝各位:新的一年,恭喜发财,万事如意[撒花]

来年我们一起努力!

本文内容由小媛整理编辑!