Dates and times are a lot more complicated than we normally realize. Having a specific data type to manage all the details is crucial.
02-04-10. What does that mean? If you’re from the US, then it probably means February 4th, 2010. But it might also mean the 2nd of April, 2010. Or is it April 10th, 1902?
There’s a group called the International Organization for Standardization and has been operating in its current form since 1947. Most people refer to the group as ISO and refer to various standards that the group produces as ISO followed by some number. The standard for dates has gone through several versions and is now known as the ISO 8601 standard. The current version is ISO 8601:2004
The standard specifies that the year comes first, then the month, and then the day. It’s actually more specific than just that. First of all, the year must be written as four digits. There’s no more mistaking 50 for either 1850, 1950, or 2050. And the months and days must both be written as two digits with a leading zero when necessary. So you don’t just write a 1 for January. It has to be a 01.
And along the same lines, the standard avoids naming the months. This is because dates when spelled out with the month names should be localized into different languages with the local name of each month for that language. By using only the Arabic numbers, we avoid any localization issues.
Because dates always start with a four digit year and then can have a 2 digit month and then can have a 2 digit day, there’s no misunderstanding.
Alright so back to those months again. In some computer systems, months can be a distraction. So why not get rid of them? We can! And the ISO 8601 standard provides two ways to do this.
The first way is to work with weeks directly. The week is a duration of seven days that’s still widely used. The only real source of confusion is what day of the week should come first? Common choices are Sunday, Monday, and even Saturday. Well, we need to pick one and the standard says Monday is the first day of the week. All we need to do then is to number each week of the year from 01 up to a maximum of 53.
If you want to refer to the first week of the year 2020, then what’s to prevent 2020-01 meaning the first week from being confused with 2020-01 meaning the first month? The standard says that in order to use week numbers, then you also need to place a capital W before the week number. You can do this with or without dashes. That means if you really want to refer to the first week in the year 2020, then the proper way to write it is 2020-W01 or just 2020W01.
Now, weeks have one more complexity. The problem is that new years don’t always begin on a Monday. What do we do when a new year begins on some day other than the first day of the week? Whenever you have a week that spans a new year, then the standard just says that week will belong to whatever year has more of its days. So if a week has 4 or more of its days in the previous year, then it belongs in the previous year. And if it has 4 or more of its days in the new year, then it belongs in the new year.
Now that you know how to define a specific week, how do you refer to a particular day in this system? If you want to, you can just refer to the week and leave the day unspecified. But if you do need to be precise, then just add a single digit either with or without a dash to represent the day. For example, to refer to the Wednesday (which is defined to be the third day) in the second week of the year 2020, you could write either 2020-W02-3 or as 2020W023 without dashes.
The final way to represent a date without using months is the easiest of them all. But it’s not something we’re used to. In this system, each day is numbered starting with 1 and going up to either 365 or 366 for leap years. You need to use leading zeros that the days always use three digits. For example, the 3rd day of the year will be number 003, and the 50th day will be number 050. Because the number of days uses three digits, there’s no confusing them with months. To write the 3rd day of the year 2020 will then be, 2020-003 or 2020003 without dashes.