mysql查詢上一天 上一小時的資料

2021-06-28 10:15:54 字數 712 閱讀 8094

檢視當前日期:

select current_date()
返回結果:2015-01-26

select now()
返回結果:2015-01-26 11:57:52

date_sub() 函式從日期減去指定的時間間隔。

date_sub(date,interval expr type)
具體可參考:

from_unixtime():unix時間戳格式化為日期函式

unix_timestamp() :日期轉時間戳

date_format(date,format):格式化日期函式

故 :

select * from 資料表 

where cdate between date_sub(date_format(current_date(),'%y-%m-%d 00:00:00'),interval 1 day) and date_format(current_date(),'%y-%m-%d 00:00:00')

select * from 資料表 where cdate between date_sub(date_format(now(),'%y-%m-%d %h:00:00'),interval 1 hour) and date_format(now(),'%y-%m-%d %h:00:00')

MYSQL查詢大於建立時間一小時的資料

以下 中times為時間字段,型別為datetime 1.查詢大於times一小時的資料 大於號後面都是獲取times一小時後的時間 select from table where now subdate times,interval 1 hour select from table where n...

揭露3 28停電一小時的陰謀

2009年3月28日晚上8 30 9 30 是 電視台並且在全球播出的慶祝 解放五十周年紀念晚會 因為2009年3月28日晚上8 30 9 30正好是 電視台並且在全球播出的慶祝 解放五十周年紀念晚會,很明顯,這個時候,所謂的環保分子發起的 地球一小時 陰謀大家可想而知,地球一小時 這個活動,為什麼...

2 Python 當前時間加一天 一小時 一分鐘

寫自動化的時候遇到這樣乙個需求,給某個日期控制項附當前日期,如果條件滿足繼續,如果不滿足,則賦下一天。1 datetime模組 print datetime.datetime.now 執行結果 2017 10 17 16 59 28.385184 2 實現下一天 下一小時 下一分鐘 下一秒 impo...