Print dates in date range linux
date, linux, shell, unix
Solution
As long as the dates are in YYYY-MM-DD format, you can compare them lexicographically, and let `date` do the calendar arithmetic without converting to seconds first:
startdate=2013-03-15
enddate=2013-04-14
curr="$startdate"
while true; do
echo "$curr"
[ "$curr" \< "$enddate" ] || break
curr=$( date +%Y-%m-%d --date "$curr +1 day" )
done
With `[ ... ]`, you need to escape the `<` to avoid confusion with the input redirection operator.
This does have the wart of printing the start date if it is greater than the end date.
Problem
I am new to linux. How can I print and store date in given date range. For example I have startdate=2013-03-01 and enddate = 2013-03-25 ; I want to print all date in that range. Thanks in advance