Skip to content

Instantly share code, notes, and snippets.

@ebongzzang
Last active February 5, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebongzzang/f576219637fdc7e3c3504d934a744017 to your computer and use it in GitHub Desktop.
Save ebongzzang/f576219637fdc7e3c3504d934a744017 to your computer and use it in GitHub Desktop.
print all dates string between startdate and enddate in mac os
#!/bin/bash
startdate=$1
enddate=$2
function print_formatted() {
res=`date -j -f %Y-%m-%d $1 +%Y-%m-%d`
echo $res
}
startfmt=$(print_formatted $startdate)
endfmt=$(print_formatted $enddate)
let j=0
while [ "$loop_date" != "$endfmt" ]; do
loop_date=`date -j -v+${j}d -f %Y-%m-%d "$startfmt" +%Y-%m-%d`
echo $loop_date
let j=j+1
done
# ./date.sh 20191231 20200105
#2019-12-31
#2020-01-01
#2020-01-02
#2020-01-03
#2020-01-04
#2020-01-05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment