3

In linux bash when I enter date -d "1986-01-01" it shows error

date: invalid date "1986-01-01"

when date -d "1986-01-02" it works

when date -d "1987-01-01" it also works

Why date -d "1986-01-01" shows error in Linux Bash shell.

I am using Fedora 16

10
  • And something like date -d "1986-01-01" "+%Y"? Commented May 1, 2013 at 9:13
  • It doesn't work shows same error Commented May 1, 2013 at 9:15
  • i have fedora 12, 14 and 15 and they are not showing such error. so i believe it's specific to f16 Commented May 1, 2013 at 9:17
  • 5
    I can reproduce your problem with TZ=Asia/Kathmandu date -d '1986-01-01'. Most likely it has something to do with the fact that Nepal changed the timezone in 1986. Commented May 1, 2013 at 9:29
  • 2
    Well done, @nosid, I think you should post this comment as an answer, as it seems to be the point. I get an invalid date from 1986-01-01 to 1986-01-01 00:09:59. 1986-01-01 00:10:00 is already OK. Commented May 1, 2013 at 9:38

2 Answers 2

11

Nepal changed its timezone at the beginning of 1986. The following table is copied from the tzdata package:

# Zone  NAME            GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Asia/Kathmandu  5:41:16 -       LMT     1920
                        5:30    -       IST     1986
                        5:45    -       NPT     # Nepal Time

That means that on Jan 1 1986 the time from 00:00:00 to 00:14:59 is not valid. The following two commands show, that the first day of 1986 started with 00:15:00:

$ TZ=Asia/Kathmandu date -d '1985-12-31 23:59:59' '+%s'
504901799
$ TZ=Asia/Kathmandu date -d '1986-01-01 00:15:00' '+%s'
504901800

So the error message of date is correct. The date is invalid in this timezone. I am not sure what you are doing with the result of this command. However, you can try to use UTC because all dates are valid and unambiguous in UTC:

$ TZ=UTC date -d '1986-01-01'
Wed Jan  1 00:00:00 UTC 1986
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I got answer in details
0

I think you are using alphabet "O" in upper case instead of number "0" in the command :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.