I need the date format in YYYY.MM format and I am able to get current month date as well as previous month date with below command
PM=`date +'%Y.%m' -d 'last month'`
CM=`date +'%Y.%m' -d 'now'`
but I need to get YYYY.MM date format for previous 12 months so could you please help me how I get that in shell scripting ?
xbin
2
I think you are looking for something like this
x=0
while [ "$x" -le 12 ]
do date +'%Y%m' -d "$x month ago"
((x++))
done
Though this doesn't assign values to a variable. Does your shell support arrays?
RudiC
3
With a recent bash or ksh you could use
printf "%(%Y.%m)T\n" $(( $(printf "%(%s)T\n") - (365 * 86400) ))
2014.07