Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security
Blackhole Pro
Blackhole Pro: Trap bad bots in a virtual black hole.
Related Posts

Best Date Format: Year Month Day

Arguably the most common way to express a date is to include the day of the month, the month, and the year. And there are many ways to order that information. For example, day, month, year, like 20/11/2020. Or perhaps a more common example is month, day, year, like 12/30/2024. Any programmer will tell you that there are endless variations and possibilities. With the scripting language PHP for example, there are many ways to format a date. So it begs the question, is there an optimal way to write dates? Why yes in fact, there is..

YEAR/MONTH/DAY format maintains perfect calendrical order and scales infinitely.

Numerical Order is the Key

For one-off dates, like when filling out a form or something, you can use whatever date format makes sense. But when working with multiple dates, like with archived files, it’s always best to write numerical dates in descending order. Doing so preserves calendrical/chronological order and is infinitely scalable. To understand this, consider some examples.

Putting the day first

When working with only one month’s worth of days at a time, it’s fine to put the day first, because all of the days will be in numerical order. For example, if you have a folder that contains one file for each day in the month of February, 2030:

01/02/2030
02/02/2030
03/02/2030
.
.
.
26/02/2030
27/02/2030
28/02/2030

And all is well. But it doesn’t scale. That is, if you add files for each day in March, the results get jumbled:

01/02/2030
01/03/2030
02/02/2030
02/03/2030
03/02/2030
03/03/2030
.
.
.
26/02/2030
26/03/2030
27/02/2030
27/03/2030
28/02/2030
28/03/2030

So the files/dates are alternating from February to March, which is confusing at best. And it gets increasingly complex as more days are added. So in addition to not scaling, day-first formats fail at preserving calendrical order.

Putting the month first

Just as with putting the day first, putting the month first in dates leads to chaos. Again let’s use the example of archived files in a folder. Including only one year’s worth of months is gonna be fine:

01/15/2040
02/15/2040
03/15/2040
.
.
.
10/15/2040
11/15/2040
12/15/2040

But as before this is not scalable. For example, adding more months with the same day begins to confuse:

01/15/2040
01/15/2041
02/15/2040
02/15/2041
03/15/2040
03/15/2041
.
.
.
10/15/2040
10/15/2041
11/15/2040
11/15/2041
12/15/2040
12/15/2041

In order to make sense of this, you have to look at the end of each line to get the year information. So again calendrical order is lost. I mean, imagine if we added more than one day per month per year:

01/15/2040
01/16/2040
01/15/2041
01/16/2041
02/15/2040
02/16/2040
02/15/2041
02/16/2041
03/15/2040
03/16/2040
03/15/2041
03/16/2041
.
.
.

Yeah good luck with that.

Year first, then day, then month

One more example of what doesn’t work. Putting the year first followed by the day then month. Consider the following, where we have a folder containing one file for each month of the year:

2020/20/01
2020/20/02
2020/20/03
.
.
.
2020/20/10
2020/20/11
2020/20/12

As with previous examples, this ordering breaks down if either more days or added or more months are added.

2020/20/01
2020/21/01
2020/20/02
2020/21/02
2020/20/03
2020/21/03
.
.
.
2020/20/10
2020/21/10
2020/20/11
2020/21/11
2020/20/12
2020/21/12

Notice how the dates alternate between 20 and 21? It’s just bonkers. So this format also is not optimal because it is not scalable and does not preserve calendrical order.

Using spelled-out names for months and days

By now you should see where this is going. But for the sake of thoroughness, let’s look at one more example, where actual names are used in dates. As before, say we have a folder that contains a file for each day of the week. Ideally it would look something like this:

Sunday-Aug-04-2019
Monday-Aug-05-2019
Tuesday-Aug-06-2019
Wednesday-Aug-07-2019
Thursday-Aug-08-2019
Friday-Aug-09-2019
Saturday-Aug-10-2019

That may look nice and even easier to read, etc. But that is not how the files actually will be ordered on the machine. Instead it would look like this:

Friday-Aug-09-2019
Monday-Aug-05-2019
Saturday-Aug-10-2019
Sunday-Aug-04-2019
Thursday-Aug-08-2019
Tuesday-Aug-06-2019
Wednesday-Aug-07-2019

Because computers order things alphanumerically, the files are out of order pretty much completely. So why bother naming them with dates in the first place. Imagine a hundred files named like this. Likewise using the spelled-out name of the month, like “September” or “October”; it just doesn’t work.

Year, month, day.

This is the best format. To understand why, consider the following example:

2020/01/20
2020/02/20
2020/03/20
.
.
.
2020/10/20
2020/11/20
2020/12/20

Now let’s add in months from another year:

2020/01/20
2020/02/20
2020/03/20
.
.
.
2020/10/20
2020/11/20
2020/12/20
2021/01/20
2021/02/20
2021/03/20
.
.
.
2021/10/20
2021/11/20
2021/12/20

Still in order. What if we add more days to each month:

2020/01/20
2020/01/21
2020/02/20
2020/02/21
2020/03/20
2020/03/21
.
.
.
2020/10/20
2020/10/21
2020/11/20
2020/11/21
2020/12/20
2020/12/21
2021/01/20
2021/01/21
2021/02/20
2021/02/21
2021/03/20
2021/02/21
.
.
.
2021/10/20
2021/10/21
2021/11/20
2021/10/21
2021/12/20
2021/10/21

Everything remains perfectly ordered. We could add as many dates as needed and the order always will remain correct. So unlike other format options, “year-month-day” is both infinitely scalable and calendrical in order.

The Principle

In general, order date items from largest to smallest to keep things scalable and preserve calendrical order. If the largest timeframe is a year, then begin the date with the year. If it is the month, then begin with the month. If centuries, begin with centuries. And so forth. Then proceed in descending order until reaching the smallest date item, whether it be the day, minute, second, nanosecond, or what have you.

It’s that simple. And as long as the format is consistent, it works regardless of punctuation: dashes, slashes, spaces, or even no punctuation at all; it always works because it is numerically consistent.

Caveat

As mentioned, there are endless ways to write a date. This article aims at answering the question, “which is best” for the general case. Like on a computer naming files. Or data in a spreadsheet. Or when writing code. Or virtually anything else you can think of.

Of course, there always are exceptions to the rule. There may be certain disciplines or fields where highly specific date formatting is required for specific algorithmic purposes, scientific analyses, or whatever. In general however, for everyday common use, the best date format begins with the largest timespan and then proceed to the smallest. And you can use whatever punctuation you want, for example:

year-month-day
year.month.day
year/month/day

In general, always use largest-to-smallest format when writing dates. Anything else doesn’t make sense.

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
.htaccess made easy: Improve site performance and security.

4 responses to “Best Date Format: Year Month Day”

  1. Jim S Smith 2019/06/08 5:50 pm

    I generally use this format – especially for sequential files when keeping track of the date of creation – within their filenames.

    Of course,

    Being that I am used to the 24-Hour time notation,

    -> yyyymmdd-hhmmssuuu

    ( The “uuu” standing in for thousandths of a second, if really needed. )

    I DO use -> date(‘Ymd – His’) a lot (along with some minor variations).

    – Jim S.

  2. Totally agree even though im from Spain i we use day/month/year format by default.

  3. I use day/month/year and always feel stucked to find my files. Thanks to your post, I set year/month/day format by default and my productivity’s improved a lot

  4. Jeff Starr 2019/12/28 3:48 pm

    To add to the post: the principle can be applied in general to organizing anything anywhere: always begin with the most overarching/comprehensive/general attribute, and then proceed downward to the most specific details/smaller attributes.

    For example, in organizing the complete location of your residence here on planet earth, we would write:

    Universe > Galaxy > Solar System > Planet > Country > State > Address

    So going with “year/month/day” ordering is just a natural extension of the “general to specific” strategy.

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
.htaccess made easy: Improve site performance and security.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.