mysql常用日期获取直接上语句
通过一个账期为基准,通过下面的语句直接实现
select v_date 账期,
date_format(date_sub(v_date,interval 1 day ),'%Y%m%d') 昨日日期,
date_format(date_sub(v_date,interval 1 month ),'%Y%m01') 上月月初1号,
date_format(date_sub(v_date,interval 1 month ),'%Y%m%d') 上月同期,
date_format(date_sub(v_date,interval day(v_date) day),'%Y%m01') 上月第一天,
date_format(date_sub(v_date,interval day(v_date) day),'%Y%m%d') 上月底最后一天,
date_format(date(concat(year(v_date),'-',elt(quarter(v_date),1,4,7,10),'-','01')),'%Y%m%d') 本季度第一天,
date_format(last_day(makedate(extract(year from v_date),1) + interval quarter(v_date)*3-1 month),'%Y%m%d') 本季度最后一天,
date_format(last_day(makedate(extract(year from v_date),1) + interval quarter(v_date)*3-6 month),'%Y%m01') 上季度第一天,
date_format(last_day(makedate(extract(year from v_date),1) + interval quarter(v_date)*3-4 month),'%Y%m%d') 上季度最后一天,
date_format(date_sub(v_date,interval 3 month ),'%Y%m%d') 上季度同期,
date_format(v_date,'%Y0101') 本年第一天,
date_format(date_sub(v_date,interval 12 month ),'%Y12') 上年底最后一月,
date_format(date_sub(v_date,interval 12 month ),'%Y%m') 上年同期月的,
date_format(date_sub(v_date,interval 6 day ),'%Y%m%d') 近7天开始日期,
date_format(date_sub(v_date,interval 0 day ),'%Y%m%d') 近7天结束日期,
date_format(date_sub(v_date,interval 13 day ),'%Y%m%d') 上7天开始日期,
date_format(date_sub(v_date,interval 7 day ),'%Y%m%d') 上7天结束日期,
date_format(date_sub(v_date,INTERVAL WEEKDAY(v_date) + 1 DAY),'%Y%m%d') 当前week第一天,
date_format(date_sub(v_date,INTERVAL WEEKDAY(v_date) - 5 DAY),'%Y%m%d') 当前week的最后一天,
date_format(date_sub(v_date,INTERVAL WEEKDAY(v_date) + 8 DAY),'%Y%m%d') 前一week的第一天,
date_format(date_sub(v_date,INTERVAL WEEKDAY(v_date) + 2 DAY),'%Y%m%d') 前一week的最后一天,
date_format(last_day(v_date),'%Y%m%d') 当月最后一天
from (select date_format(adddate(current_date,-1),'%Y%m%d') v_date ) a;