"$date" in year 2000 flaw?

Posted on 2000-03-26
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
  • 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 75 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now