bug-coreutils
[Top][All Lists]
Advanced

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

Re: date


From: Bob Proulx
Subject: Re: date
Date: Wed, 31 Dec 2008 10:33:02 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

Jeremy M. Guthrie wrote:
> I have found a bug with 'date', it will jump a year the last few days of the 
> year.

Thank you for your report.  But the behavior you are reporting is not
a bug but a misunderstanding of the date format specifications.

> #The actual time/date
> [h-custmgmt-msn-1 guthrie 10:09am]~-> date
> Wed Dec 31 10:09:34 CST 2008  

This probably isn't the issue but the default legacy date format is
ambiguous.  CST isn't unique.  For future reference using -R is a
better format and is found my places such as in mail date strings and
so forth.  This is just a hint for the future.

  $ date -R
  Wed, 31 Dec 2008 10:28:33 -0700

> #It thinks it's 2009.  It did this yesterday and the day before.
> [h-custmgmt-msn-1 guthrie 10:09am]~-> date "+%m-%d-%G"
> 12-31-2009
> [h-custmgmt-msn-1 guthrie 10:09am]~-> date "+%G"
> 2009

That is true all week long.  The %G is as shown:

  `%G'
       The year corresponding to the ISO week number.  This has the same
       format and value as `%Y', except that if the ISO week number (see
       `%V') belongs to the previous or next year, that year is used
       instead.  This is a GNU extension.

The ISO week number is 2009.  What you wanted was %Y if you wanted the
year in the current calendar year.

  `%Y'
       year.  This is normally at least four characters, but it may be
       more.  Year `0000' precedes year `0001', and year `-001' precedes
       year `0000'.


Try this:

  $ date "+%m-%d-%Y"
  12-31-2008

Or better yet use the %F format specifying to use the full date in ISO
format.  This is a GNU extension.

  $ date +%F
  2008-12-31

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]