#!/bin/bash
#开始日期,时间格式形如:2019-02-28 08:20:30
startTime="2018-05-01 00:00:00"
startMonth=`date -d "${startTime}" +"%Y%m"`
#结束日期,时间格式形如:2019-06-12 16:22:59
endTime="2019-04-12 12:30:57"
endMonth=`date -d "${endTime}" +"%Y%m"`
echo "sync startTime[${startTime}], endTime[${endTime}]"
#重置startMonth,如统计3,4月份的季度信息,则要统计2个季度:1~3月为第一个季度,4月为第二季度(4~6月)
startMM=`date -d "${startTime}" +"%m"`
if [ ${startMM} == 02 ] || [ ${startMM} == 03 ];then
startMonth=`date -d "${startTime}" +"%Y01"`
elif [ ${startMM} == 05 ] || [ ${startMM} == 06 ];then
startMonth=`date -d "${startTime}" +"%Y04"`
elif [ ${startMM} == 08 ] || [ ${startMM} == 09 ];then
startMonth=`date -d "${startTime}" +"%Y07"`
elif [ ${startMM} == 11 ] || [ ${startMM} == 12 ];then
startMonth=`date -d "${startTime}" +"%Y10"`
fi
#根据开始月份与结束月份,获取季度信息等
quarterOfYear=2000Y-1Q
while [ ${startMonth} -le ${endMonth} ]
do
startMM=${startMonth:4:2}
if [ ${startMM} == 01 ];then
quarterOfYear=${startMonth:0:4}Y-1Q
elif [ ${startMM} == 04 ];then
quarterOfYear=${startMonth:0:4}Y-2Q
elif [ ${startMM} == 07 ];then
quarterOfYear=${startMonth:0:4}Y-3Q
elif [ ${startMM} == 10 ];then
quarterOfYear=${startMonth:0:4}Y-4Q
fi
tempFirstStartDay=${startMonth}01
tempEndMonth=`date -d "${tempFirstStartDay} 2 months" +"%Y%m"`
if [ ${tempEndMonth} -gt ${endMonth} ];then
tempEndMonth=${endMonth}
fi
echo "cureent quarter[${quarterOfYear}], query date range[${startMonth},${tempEndMonth}]"
tempFirstEndDay=${tempEndMonth}01
startMonth=`date -d "${tempFirstEndDay} 1 months" +"%Y%m"`
done
还没有评论,来说两句吧...