Hi. I want to do some calendar manipulations in bash - specifically, I want to figure out the last date of a given month (including leap-year, and a preparing a table for a lookup is not a valid solution for me).
Supposedly I have the following code:
$year=2009
$start_month=2
$end_month=10
for $month in $(seq $start_month $end_month); do
echo "Last date of "$(date +"%B" -d "${year}-${month}-01")" is: " ???
done
I can't figure out how to do something like this. I though date -d
would work like POSIX mktime and fold invalid dates to their valid equivalents, so I could say something like date -d "2009-03-00"
and get '2009-02-28', but no such luck.
Is there anyway to do it using only what is available on bash in a standard GNU environment?