mysql中的日期函数_sql获取当前日期函数

(2) 2024-09-09 18:23

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
mysql中的日期函数_sql获取当前日期函数,希望能够帮助你!!!。

前面,两篇分别介绍了,MySQL的字符串函数和数值函数,接下来,一起学习下日期函数,走起[奸笑]

上图

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第1张

1.NOW()获取当前时间

SQL语句:SELECT NOW() as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第2张

2.YEAR()获取当前年份

SQL语句:SELECT YEAR(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第3张

3.MONTH()获取当前月份

SQL语句:SELECT MONTH(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第4张

4.WEEK()获取当前是今年的第几周

SQL语句:SELECT WEEK(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第5张

5.DAY()获取本月几号

SQL语句:SELECT DAY(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第6张

6.HOUR()获取当前小时

SQL语句:SELECT HOUR(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第7张

7.MINUTE()获取当前分钟

SQL语句:SELECT MINUTE(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第8张

8.MONTHNAME()返回英文月份

SQL语句:SELECT MONTHNAME(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第9张

9.CURDATE()返回当前日期,只包含年月日

SQL语句:SELECT CURDATE() as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第10张

10.CURTIME() 返回当前时间,只包含时分秒

SQL语句:SELECT CURTIME() as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第11张

11.UNIX_TIMESTAMP()返回时间戳

SQL语句:SELECT UNIX_TIMESTAMP(NOW()) as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第12张

12.FROM_UNIXTIME()返回对应时间戳的日期值

SQL语句:SELECT FROM_UNIXTIME() as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第13张

13.DATE_FORMAT(date,format)格式化 日期函数

SQL语句:SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第14张

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

SQL语句:SELECT DATEDIFF('1995-11-06','1994-09-22') as temporary_time

mysql中的日期函数_sql获取当前日期函数_https://bianchenghao6.com/blog__第15张

收工[鼓掌]

年前最后一更[奸笑]

新年快乐!

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

来年我们一起努力!

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

上一篇

已是最后文章

下一篇

已是最新文章

发表回复