Code Snippet
- # default output format, change as necessary
- defaultof="%Y%m%d"
- # check for input format, else use default format,
- # refer to 'man date' for help on format
- # script only supports %Y %m %d at the moment
- of=$defaultof
- [ $# -eq 1 ] && of="$1"
- # get today's date
- eval "`date +'y=%Y m=%m d=%d'`"
- #check for max number of days in current month
- days=31
- if [ $m -eq 4 ] || [ $m -eq 6 ] || [ $m -eq 9 ] || [ $m -eq 11 ] ; then
- days=30
- fi
- # check for leap year if feb
- if [ $m -eq 2 ]; then
- days=28
- leap1=`expr $y % 4`
- leap2=`expr $y % 100`
- leap3=`expr $y % 400`
- if [ $leap1 -eq 0 ] ; then
- if [ $leap2 -gt 0 ] || [ $leap3 -eq 0 ] ; then
- days=29
- fi
- fi
- fi
- # increment date
- if [ $d -eq $days ]; then
- d=1
- m=`expr $m + 1`
- if [ $m -eq 13 ]; then
- m=1
- y=`expr $y + 1`
- fi
- else
- d=`expr $d + 1`
- fi
- #Solaris date does not accept -d
- #date -d "$y-$m-$d" +"$of"
- eval "y=`expr $y + 0` m=`expr $m + 0` d=`expr $d + 0`"
- eval "y=`printf "%04d" $y` m=`printf "%02d" $m` d=`printf "%02d" $d`"
- tomorrowsDate="${d}${m}${y}"
End of snippet
No comments:
Post a Comment