On 29 March 2011 16:55, James Bensley jwbensley@gmail.com wrote:
Can anyone explain this?
[user@machine ~]$ date Tue Mar 29 16:48:38 BST 2011 [user@machine ~]$ date --date="1 month ago" Tue Mar 1 15:48:47 GMT 2011
Shouldn't that last one say the date one month ago, not 28 days ago?
What would you expect it to say?
The date "one month" before the 28th March is clearly the 28th Feb The date "one month" before 1 April is clearly the 1st Mar There is plenty of wiggle room on the 29th, 30th, 31st Mar. It's either the 28th Feb or 1 Mar, it looks like the authors of 'date' have chosen the latter, though the decision is quite arbitrary, IMHO.
Previously, when I've wanted "the end of last month" programmatically, I've taken the current date, set the day of the month to 1, then subtracted 1 to get the previous month. Date arithmetic is a right PITA, IMHO.
Greg [Resent to the list, this time. Oops]