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?
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]
On 29 March 2011 17:20, Greg Thomas Greg@thethomashome.co.uk wrote:
[snip snip]
Date arithmetic is a right PITA, IMHO.
Greg
Quite right.. Imagine what happens when you throw in academic years (September to September) with school holidays and then financial years too...!
Absolute chaos ensues... Lesson: don't attempt to help the finance department in an educational institution(!) I don't know how they do it.
-Simon
On Tue, Mar 29, 2011 at 04:55:35PM +0100, 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?
Isn't '1 month ago' 28 days when the 'last' month was February?
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 ------------------------------
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?
http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-dat...
Regards, Mike.