I want to do some calendar manipulations in bash - in particular, I want to find out the last date of a given month (including a leap year, and preparing a table for a search is an invalid solution for me).
Presumably 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 this. Although I date -dwould work as POSIX mktime and fold invalid dates with their valid equivalents, so I could say something like date -d "2009-03-00"and get "2009-02-28", but there wasn’t such luck.
Is there a way to do this using only what is available on bash in the standard GNU environment?
source
share