mysql日期查詢

2022-08-22 02:36:07 字數 1653 閱讀 4991

--

查詢昨日一整天的資料

select date_format(date_sub(now(),interval 1

day) ,'

%y-%m-%d 00:00:00

') as

'昨日開始時間

' ,date_format(date_sub(now(),interval 1

day) ,'

%y-%m-%d 23:59:59

') as

'昨日結束時間'--

查詢今日開始到當前時間的資料

select date_format(date_sub(now(),interval 0

day) ,'

%y-%m-%d 00:00:00

') as

'今日開始時間

' ,date_format(date_sub(now(),interval 0

day) ,'

%y-%m-%d %h:%i:%s

') as

'今日當前時間'--

查詢上月一整個月的資料

select date_format(date_sub(now(),interval 1

month) ,'

%y-%m-01 00:00:00

') as

'上個月開始時間',

date_sub(date_sub(date_format(now(),

'%y-%m-%d 23:59:59

'),interval extract( day

from now()) day),interval 0

month) as

'上個月結束時間'--

查詢本月開始到當前時間的資料

select date_format(date_sub(now(),interval 0

month) ,'

%y-%m-01 00:00:00

') as

'本月開始時間

' ,date_format(date_sub(now(),interval 0

day) ,'

%y-%m-%d %h:%i:%s

') as

'本月當前時間'--

查詢去年一整年的資料

select date_format(date_sub(now(),interval 1

year) ,'

%y-01-01 00:00:00

') as

'去年開始時間',

date_format(date_sub(now(),interval

1year) ,'

%y-12-31 23:59:59

') as

'去年結束時間'--

查詢本年開始到當前時間的資料

select date_format(date_sub(now(),interval 0

day) ,'

%y-01-01 00:00:00

') as

'本年開始時間

' ,date_format(date_sub(now(),interval 0

day) ,'

%y-%m-%d %h:%i:%s

') as

'本年當前時間

'

**

mysql日期查詢 mysql 查詢日期

檢視本月資料 select from content publish where date format publish time,y m date format date sub curdate interval 0 month y m 檢視上個月資料 select from content pu...

mysql 日期查詢 Mysql日期查詢list

當前week的第一天 select date sub curdate interval weekday curdate 1 day 當前week的最後一天 select date sub curdate interval weekday curdate 5 day 前一week的第一天 select...

MySQL 日期查詢

在mysql使用過程中,日期一般都是以datetime timestamp等格式進行儲存的,但有時會因為特殊的需求或歷史原因,日期的儲存格式是varchar,那麼我們該如何處理這個varchar格式的日期資料呢 時間欄位為greens data 型別為 varchar 1 第一種 函式str to ...