codecamp

MySQL 查看当月所有日期

select date from (

SELECT DATE_FORMAT(DATE_SUB(last_day(curdate()), INTERVAL xc-1 day), '%Y-%m-%d') as date

FROM ( 

SELECT @xi:=@xi+1 as xc from 

(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc1, 

(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc2,  

(SELECT @xi:=0) xc0 

) xcxc) x0 where x0.date >= (select date_add(curdate(),interval-day(curdate())+1 day)); 


输出结果:

"date" 

"2022-02-28" 

"2022-02-27" 

"2022-02-26" 

"2022-02-25" 

"2022-02-24" 

"2022-02-23" 

"2022-02-22" 

"2022-02-21" 

"2022-02-20" 

"2022-02-19" 

"2022-02-18" 

"2022-02-17" 

"2022-02-16" 

"2022-02-15"

"2022-02-14"

"2022-02-13"

"2022-02-12"

"2022-02-11"

"2022-02-10" 

"2022-02-09"

"2022-02-08"

"2022-02-07"

"2022-02-06"

"2022-02-05"

"2022-02-04"

"2022-02-03"

"2022-02-02"

"2022-02-01"


MySQL 自动生成一个日期表
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }