0

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?

Ayan Biswas
  • 1,641
  • 9
  • 39
  • 66
  • 2
    I've tried it and it works in my environment. Output: ``2022-03-02 2022-03-03 2022-03-04 2022-03-05 2022-03-06 `` – David Lukas Mar 10 '22 at 15:26
  • 3
    the code works for me; the issue is likely with your version of `date`; what does `date --version` report? – markp-fuso Mar 10 '22 at 15:30
  • offtopic: I would rename `start` to something like `loopdate`. Most people will expect a start value to be fixed. – Walter A Mar 12 '22 at 15:33

1 Answers1

0

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