Getting next month with date command?
bash, date
Solution
From the GNU man pages:
The fuzz in date units can cause problems with relative items. For example, ‘2003-07-31 -1 month’ might evaluate to 2003-07-01, because 2003-06-31 is an invalid date. To determine the previous month more reliably, you can ask for the month before the 15th of the current month
You can use a day which exists in all months:
date +"%B %Y" --date="$(date +%Y-%m-15) next month"
Result:
April 2014
Problem
I had this in one of my scripts which I'm sure has been working for ages. Today its saying next month is May? ``` #date Mon Mar 31 15:30:13 BST 2014 #date +"%B %Y" --date="+1 month" May 2014 ``` Anyone know what the problem is - is there a better "next month" script I should use?