Created
September 17, 2019 14:02
-
-
Save leberblock/b321482b66b3ac4845080361e9321eda to your computer and use it in GitHub Desktop.
shell: date command identify last 3 previous months
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 | |
set -x | |
echo "[$(date "+%Y-%m-%d %H:%M:%S")] started ..." | |
# set date | |
month=$(date +"%-m") | |
month_prev=$((month - 3)) | |
month_end=$month | |
month_start=$(date -d "$(date +%Y-%m-1) -3 month" +%-m) | |
year=$(date +"%Y") | |
year_prev=$(date -d "$(date +%Y-%m-1) -1 year" +%-Y) | |
year_end=$year | |
# year_start | |
if [ $month -eq 1 ] || [ $month -eq 2 ] || [ $month -eq 3 ]; then | |
year_start=$year_prev | |
else | |
year_start=$year | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment