
| From: mwilson--- via talk <talk@gtalug.org> | Discovered when I ran my script to run pcal and refresh my next-month | calendar, and got March. | | | mwilson@ningabel:~$ date | Tue 30 Jan 2024 04:23:27 PM EST | mwilson@ningabel:~$ date -d'this month' +%m | 01 | mwilson@ningabel:~$ date -d'next month' +%m | 03 | mwilson@ningabel:~$ which date | /usr/bin/date I never knew you could do this with date(1). The man page punts to the info pages (yuck). I think that "next month" adds the length of the current month to the time. This is a 31-day month, we're quite late in it, so this hops over all of February. $ date Tue 30 Jan 2024 06:46:05 PM EST $ date -d'this month' Tue 30 Jan 2024 06:46:10 PM EST $ date -d'next month' Fri 01 Mar 2024 06:46:17 PM EST What you want to do is go back to the first of the month (all modern months have a first) and then leap ahead a month. $ date --date="$(date +%Y-%m-01) next month" Thu 01 Feb 2024 12:00:00 AM EST $ date --date="$(date +%Y-%m-01) next month" +%m 02 The phony natural language that date accepts is a hazard.