mysql怎么查詢某天的數(shù)據(jù)

方法:1、用“date_format”函數(shù),語法“where date_format(date,’%Y-%m-%d’)=’年-月-日’”;2、用datediff函數(shù),語法“WHERE(datediff(time,’年-月-日’)=0)”。

mysql怎么查詢某天的數(shù)據(jù)

本教程操作環(huán)境:windows10系統(tǒng)、mysql8.0.22版本、Dell G3電腦。

mysql怎么查詢某天的數(shù)據(jù)

1、DATE_FORMAT函數(shù)

WHERE(datediff(time,’年-月-日’)=DATE_FORMAT() 函數(shù)用于以不同的格式顯示日期/時(shí)間數(shù)據(jù)。

語法

DATE_FORMAT(date,format)

date 參數(shù)是合法的日期。format 規(guī)定日期/時(shí)間的輸出格式。

示例如下:

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

2、DATEDIFF函數(shù)

DATEDIFF() 函數(shù)返回兩個(gè)日期之間的天數(shù)。

語法

DATEDIFF(date1,date2)

date1 和 date2 參數(shù)是合法的日期或日期/時(shí)間表達(dá)式。

示例如下:

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

擴(kuò)展知識(shí):

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?&gt;?'2017-09-27'?and?update_time?<p>推薦學(xué)習(xí):<a href="https://www.php.cn/course/list/51.html" target="_blank" textvalue="mysql視頻教程">mysql視頻教程</a></p>

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊9 分享