The date function on OS X (Snow Leopard) does not have the --date option like the GNU version and I am not able to figure out how to get the equivalent of the following on OS X:
startdate=2010-01-01
enddate=2010-01-31
foldate="$startdate"
until [ "$foldate" == "$enddate" ]
do
# do something with the date here - like pass it as a parameter to a command
foldate=`/bin/date --date "$foldate 1 day" +%Y-%m-%d`
done
SOLVED with answers from SiegeX:
startdate=2010-01-01
enddate=2010-01-31
sDateTs=`date -j -f "%Y-%m-%d" $startdate "+%s"`
eDateTs=`date -j -f "%Y-%m-%d" $enddate "+%s"`
dateTs=$sDateTs
offset=86400
while [ "$dateTs" -le "$eDateTs" ]
do
date=`date -j -f "%s" $dateTs "+%Y-%m-%d"`
printf '%s\n' $date
dateTs=$(($dateTs+$offset))
done