On 29-Mar-11 15:55:35, James Bensley 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? (I suppose one month needs to be quantified). Not sure how 'date' has worked that out but I'm guessing the change in time zone might perhaps be to blame?
Can anyone shed some light on this?
-- James.
http://www.jamesbensley.co.cc/ There are 10 kinds of people in the world; Those who understand Vigesimal, and J others...?
This issue seems to have been anticipated in 'info date'. Enter info date and go to the section "* Relative items in date strings:: next tuesday, 2 years ago."
There you will read, first:
The unit of time displacement may be selected by the string `year' or `month' for moving by whole years or months. These are fuzzy units, as years and months are not all of equal duration. More precise units are `fortnight' which is worth 14 days, `week' worth 7 days, [...]"
Then, further down towards the end:
The fuzz in 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. For example:
$ date -R Thu, 31 Jul 2003 13:02:39 -0700 $ date --date='-1 month' +'Last month was %B?' Last month was July? $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!' Last month was June!
Hoping this helps. Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 29-Mar-11 Time: 17:35:16 ------------------------------ XFMail ------------------------------