取几天的日期,shell
时间:2007-12-24 来源:bkj
这是一个求2天前的另一个例子,需要求n天前的数据可自行修改
!bin#/sh
TODAY=20`date +%y``date +%m``date +%d`
YESTEDAY=0
YEAR=`date +%y`
MONTH=`date +%m`
DAY=`date +%d`
if [ "$DAY" -le 02 ]
then
case $MONTH in
01) YESTEDAY=20"$YEAR"12`expr "$DAY" + 29`
;;
02) YESTEDAY=20"$YEAR"01`expr "$DAY" + 29`
;;
03) YESTEDAY=20"$YEAR"02`expr "$DAY" + 26`
;;
04) YESTEDAY=20"$YEAR"03`expr "$DAY" + 29`
;;
05) YESTEDAY=20"$YEAR"04`expr "$DAY" + 28`
;;
06) YESTEDAY=20"$YEAR"05`expr "$DAY" + 29`
;;
07) YESTEDAY=20"$YEAR"06`expr "$DAY" + 28`
;;
0 YESTEDAY=20"$YEAR"07`expr "$DAY" + 29`
;;
09) YESTEDAY=20"$YEAR"08`expr "$DAY" + 29`
;;
10) YESTEDAY=20"$YEAR"09`expr "$DAY" + 28`
;;
11) YESTEDAY=20"$YEAR"10`expr "$DAY" + 29`
;;
12) YESTEDAY=20"$YEAR"11`expr "$DAY" + 28`
;;
*) echo "$YESTEDAY" Occured error >> error.log
exit 1
;;
esac
else
YESTEDAY=`expr "$TODAY" - 2`