[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


"$date" in year 2000 flaw?

Posted on 2000-03-26
Medium Priority
Last Modified: 2010-04-20
The command "date" states that when setting the time and date that the order is Month,Day, Hour, Minute, Year.
There is only two entries for the year "yy" . This means that unix would not be Y2K compliant.
     Can someone tell me if the "date" command has evolutionized to y2k or not. I am deeply greatful for any response. Thank you.

Question by:tionik
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 40

Expert Comment

ID: 2659569
While it might not seem so on casual examination, Unix does know that 00 as the year in the "date" command must be 2000. And it knows this because the epoc for Unix is something like 1972 or so. There simply weren't any Unix boxes earlier than that, therefore 00 has to be 2000, it can't possibly be 1900. Now what would happen in 3000... I think we've got enough to time to solve that one.

Author Comment

ID: 2662116
This is a question I know ,and I am quizing you on it.

Accepted Solution

philiph_elvis earned 300 total points
ID: 2662342
Unix systems keep time internally as the number of seconds since the "epoch", which is defined as 00:00:00, Jan 1, 1970.

This number is stored as a 32 bit integer, thus it will overflow some time in 2038.

The "date" command converts from this internal representation to some other format.  By default, "date" shows the years as "YY".  This is just a display function - you could use "date +%Y" instead and see the full four digit year instead - 2000.

Thus no matter how the date command works, the internal representation of time is y2k-compliant.

The gnu version on date on my linux box takes either 2 or 4 digit years when setting the time.  It appears that if you only give it only two year numbers, the range can be between 00 and 59, however that seems to be ingored on my system - the year isn't actually changed.  you have to specify the full 4 digit year to actually change the year.  I think the two digit year is accepted and ignored for compatibility with other versions of date.

So on linux, use four digit numbers when setting the date.
LVL 40

Expert Comment

ID: 2662484
Okay let me try one more time. The date command is Y2K okay as Unix will not allow the date to be set earlier than the Unix epoc, which is 00:00 UCT 1 Jan 1970 on most maintream implementations. This means that years between 72 and 99 are dates in the range 1972-1999, years above 00 will be 2000 & greater. At least until 2038 at the moment on most implementations.

I don't have a large sample to play with but each Unix that do have access to returns "Bad date format" for years prior to the epoc or greater than 38 (2038). And the reason for this is that Unix doesn't keep the "date" internally in the form you might think. It stores the date as the number of tics or seconds since the epoc. This removes any Y2K concerns from the internal timekeeping (Unix was Y2K okay from the git-go), user applications may not have been. At present the only date we have to worry about will be 2038 or there abouts, which would be when the storage for clock ticks (typically a long) will overflow.

Oh yeah, I don't know what Unix you are on, but Solaris, Linux, & Irix optionally allow the specification of the century, Something like: "date [OPTION] [MMDDhhmm[[CC]YY][.ss]] "

Author Comment

ID: 2671837
Goog Job.
GNU "$date" is now in [mm,dd,tttt,cc,yy].
Focus on    ^
"cc" is for a two digit entry for the century. Such as (19)99 or (20)00.

                    Extremely well done!


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question