Last active
February 5, 2020 10:48
-
-
Save ebongzzang/f576219637fdc7e3c3504d934a744017 to your computer and use it in GitHub Desktop.
print all dates string between startdate and enddate in mac os
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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