'Finding All Dates Between Two Dates in Bash
I am trying to get all the dates that fall between a start and end date. This is what I did
start="2022-03-02"
end="2022-03-07"
while [[ $start < $end ]]
do
echo "$start"
start=$(date -d "$start + 1 day" +"%Y-%m-%d")
done
This results in an error
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
What is it I am missing?
Solution 1:[1]
inspired by this answer
You can try this if you using on MacOs
date -j -v+1d -f %Y-%m-%d $start +%Y-%m-%d
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Karan Gupta |
