Date format lost padding
I have a script that needs to input a start and end date. It works fine until the end of of the month when the start date is say April 30 and the end date is May 1.
My soliton was to check if the second day is smaller then the first, if so, take "1" away from the month. The problem is, I loose the "0" padding on single digit months and I need it to be 2 i.e April needs to be "04", not "4"
I did this little test script up to show what I mean. (If I just use `date +%m` all is fine, if I use "$((`date +%0m`-1))" I loose the padding)
#!/bin/ksh/
clear
echo
echo "Starting day i.e 11"
read date1
echo
echo "Ending day i.e 12"
read date2
echo
if [ $date2 -lt $date1 ]
then
month1="$((`date +%0m`-1))"
else
month1=`date +%m`
fi
echo "The first date is $date1/$month1, and the second date is $date2/`date +%m`."
Any ideas?
|