#!/bin/bash
date_yesterday=`date -d '1 day ago' +%Y%m%d`
date_today=`date -d '0 day ago' +%Y%m%d`
#最近7天
date_before_7day=`date -d '7 day ago' +%Y%m%d`
#上一个完整周(周一到周日)
OFDAY="`date "+%u"`"
STEPOFDAY="`expr $OFDAY + 6`"
date_before_weekday="`date -d '-'$STEPOFDAY' day' "+%Y-%m-%d"`"
date_before_weekday_end="`date -d '-'$OFDAY' day' "+%Y-%m-%d"`"
#本月
date_this_month=`date +%Y%m01`
#上一个完整月
date_before_month=`date -d '1 month ago' +%Y%m01`
#最近三个月
date_before_3month=`date -d '3 month ago' +%Y%m01`
#上个季度
echo "当天:$date_yesterday"
echo "最近7天:$date_before_7day - $date_yesterday"
echo "上一个完整周:$date_before_weekday - $date_before_weekday_end"
echo "本月内:$date_this_month - $date_today"
echo "上个完整月:$date_before_month - $date_this_month"
---------------------
转载https://blog.csdn.net/xcl_rockman/article/details/73127604