mysql怎么查询某天的数据

来自:互联网
时间:2022-05-16
阅读:

MySQL怎么查询某天的数据

1、DATE_FORMAT函数

WHERE(datediff(time,'年-月-日')=DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。

语法

DATE_FORMAT(date,format)

date 参数是合法的日期。format 规定日期/时间的输出格式。

示例如下:

select * from [table_name] where date_format([date_name],'%Y-%m-%d') = '2022-05-13'

2、DATEDIFF函数

DATEDIFF() 函数返回两个日期之间的天数。

语法

DATEDIFF(date1,date2)

date1 和 date2 参数是合法的日期或日期/时间表达式。

示例如下:

SELECT * FROM [table_name] WHERE ( datediff ( update_time , '2022-05-13' ) = 0 )

扩展知识:

SELECT * FROM [table_name] WHERE substring(Convert(char(10),update_time ,112),1,8)='20220513' 
SELECT * FROM [table_name] WHERE update_time between '2022-05-13 00:00:00' and '2022-05-13 23:59:59' 
SELECT * FROM [table_name] WHERE year(update_time ) = 2022 and month(update_time )= 05 and day(update_time ) = 13
SELECT * FROM [table_name] WHERE update_time > '2017-09-27' and update_time < '2022-05-13'
返回顶部
顶部