[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: date bug?



On 05/31/2010 12:44 PM, Camaleón wrote:
On Mon, 31 May 2010 17:34:12 +0000, T o n g wrote:

Please take a look at the following, do you think it is bug of date?

(...)

$ date --date='next month'
Thu Jul  1 11:07:31 EDT 2010

I was hoping to get June.

But June has not "31 days" so the closest is indeed "1st July" ;-)

Is it a bug, or there are other ways to get the correct answer?

It's a "feature" when playing with relative time :-)

***
info date (Relative items in date strings)

(...)

When a relative item causes the resulting date to cross a boundary
where the clocks were adjusted, typically for daylight saving time, the
resulting date and time are adjusted accordingly.

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:
***


When, on the last day of the current month, one enters the command "date --date='1 month ago'", one should see the last day of the previous month.

For example, in the RDBMS that I use at work:
SQL> SELECT CURRENT_DATABASE, CURRENT_DATE - INTERVAL'1' MONTH
cont> FROM RDB$DATABASE;

 2010-05-31   2010-04-30
1 row selected
SQL>

--
Dissent is patriotic, remember?


Reply to: