Skip to content

Instantly share code, notes, and snippets.

@claudinei-daitx
Created January 19, 2018 18:37
Show Gist options
  • Save claudinei-daitx/f85687d537813c565038a0dae01c3e80 to your computer and use it in GitHub Desktop.
Save claudinei-daitx/f85687d537813c565038a0dae01c3e80 to your computer and use it in GitHub Desktop.
Get the penultimate Wednesday of the month
#!/bin/bash
start_date=$1
end_date=$2
current_date=
counter=0
index=0
until [ "$current_date" = "$end_date" ]
do
((counter++))
current_date=$(date -d "$start_date + $counter days" +%Y%m%d)
mydate=$(date -d "$start_date + $counter days" +%w)
if [ $mydate -eq 3 ] ; then
dates[index]=${current_date}
((index++))
fi
done
array_size=${#dates[@]}
((array_size--))
((array_size--))
echo ${dates[array_size]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment