Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leberblock/b321482b66b3ac4845080361e9321eda to your computer and use it in GitHub Desktop.
Save leberblock/b321482b66b3ac4845080361e9321eda to your computer and use it in GitHub Desktop.
shell: date command identify last 3 previous months
#!/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