Should work in any shell, but requires GNU date, although GNU date seems only to be happy for input dates between 1902 and 2037, inclusive (49673 days).
Assume $a and $b hold two dates, e.g.
set a=2010-03-27
set b=2010-04-04
Marginally faster:
iterator: seq -f "$a +%1.0f days" 1 50000 | date +%F -f - 2>&1 | grep -F -B50000 -m1 `date +%F -d"$b"`
count: seq -f "$a +%1.0f days" 1 50000 | date +%F -f - 2>&1 | grep -F -B50000 -m1 `date +%F -d"$b"` | wc -l
More elegant:
iterator: yes | sed -n = | sed -e "s/.*/$a +& days/" | date +%F -f- 2>&1 | sed /`date +%F -d"$b"`/q
count: yes | sed -n = | sed -e "s/.*/$a +& days/" | date +%F -f- 2>&1 | sed -n /`date +%F -d"$b"`'/{=;q}'
For newbies, to use the iterator, simply do something like:
yes | sed -n = | sed -e "s/.*/$a +& days/" | date +%F -f- 2>&1 | sed /`date +%F -d"$b"`/q | while read date; do
echo "$date is in the range" # or whatever
done
Hope someone finds this useful.