Konubinix' opinionated web of thoughts

Date - First and Last Day of a Month

Fleeting

l_first_date=\((date -d “`date +%Y%m01` -1 month” +%Y-%m-%d) l_last_date=\)(date -d “`date +%Y%m01` -1 day” +%Y-%m-%d)

t_first_date=\((date +%Y-%m-01) t_last_date=\)(date -d “`date +%Y%m01` +1 month -1 day” +%Y-%m-%d)

n_first_date=\((date -d “`date +%Y%m01` +1 month” +%Y-%m-%d) n_last_date=\)(date -d “`date +%Y%m01` +2 month -1 day” +%Y-%m-%d)

echo “Last month: $l_first_date to $l_last_date” echo “This month: $t_first_date to $t_last_date” echo “Next month: $n_first_date to $n_last_date”

https://unix.stackexchange.com/questions/43264/first-and-last-day-of-a-month