01、取当前周的周一:select
date_add(next_day(current_date,
'MO'),
-7)
当前日期(2021-07-27)返回结果:
02、整理日期格式:取当前日期年月:
select
date_format(current_date,
'yyyy-MM');
返回结果:
03、取当月最后一天:
select
last_day(current_date)
返回结果:
04、 年度第几周函数(周一至周日,新年第一周划分以超过4天的那周所在年为准):select
weekofyear(current_date)
返回结果:
05、取周四至周三的周期数据:
select weekofyear(date_sub('2021-07-28',3))
减3天则为周一至周日,原统计日志为周四至周三,满足需求。
06、取年&周数据:
select
year(date_sub(next_day(current_date,
'MO'),
4))*100+weekofyear(current_date) deal_week