bug-coreutils
[Top][All Lists]
Advanced

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

date -d20060229 gives: "invalid date"


From: Steve Cousins
Subject: date -d20060229 gives: "invalid date"
Date: Mon, 28 Aug 2006 16:43:15 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

date Versions 5.96 and 5.97 (at least) have a bug when passing dates
that are greater than the actual number of days in a month.  Previous
versions (most of the machines seem to have 5.2.1) would convert the
date to a correct date.  For instance date -d20060229 would provide data
for March 1.

I use this in scripts that I pass a date to as a parameter:

   let NEXT_DAY=$1+1
   NEXT_DATE=`date -d$NEXT_DAY +%Y%m%d`

and:

   let PREV_DAY=$1-1
   PREV_DATE=`date -d$PREV_DAY +%Y%m%d`

In this case it might do: date -d20060200 which would turn into Jan 31.

Maybe this is an undocumented feature that someone thought was a bug.
In my case it is very useful .

Since this isn't working I figured there must be another way to do this
so I started playing around and found:

    date -d"20060228 + 1 day"

and this does do what I want.  However:

    date -d"20060201 - 1 day"

does not work.  It reports Feb 2.

Steve


--
______________________________________________________________________
 Steve Cousins, Ocean Modeling Group    Email: address@hidden
 Marine Sciences, 452 Aubert Hall       http://rocky.umeoce.maine.edu
 Univ. of Maine, Orono, ME 04469        Phone: (207) 581-4302






reply via email to

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