Practice under pressure« an older post
a newer one »Ordinary

The right way to write dates in files

Blog

When I write dates in file names, I use the format YYMMDD. I picked this style up from Yosufi, who used it to name files when Windows was the popular operating system, and you had only eight + three letters for file names. He would use two letters and the date, for the eight letters, and three letters for the extension. The two letters were meaningful to him, usually about the contents of the files.

  mg050302.doc
  mg050303.txt

I continued the numbering scheme because the date lists correctly when sorted in a directory listing. If I named the files like everyone else, they wouldn't list correctly. As an example, how about a database dump from this month, last month and the month before. If I used the format that most people seem to use, they would list like this:

  dump_011009.sql
  dump_020809.sql
  dump_122208.sql

That is clearly not in the order I want to see them, which would be in creation order. Worse, what if I had dumps from this time last year, too?

  dump_011009.sql
  dump_011108.sql
  dump_020809.sql
  dump_042908.sql
  dump_122208.sql

Now, which files, at a glance, are the most current? I can't tell. I can't tell at a glance if the database dump for this month happened. Better to use the year first, followed by month, then day. All of the files list correctly:

  dump_080111.sql
  dump_080429.sql
  dump_081222.sql
  dump_090110.sql
  dump_090208.sql

So, next time you decide to write a date in a file name use the year, month THEN day in the filename. Trust me on this.

Comments

We actually had a huge discussion about this at work. I use your format, with one twist - I use a 4 digit year. Oh, I also put hyphens in between the year, month, and day. If anyone gives you shit, tell them it's the ISO date format.