Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is your favorite date and time format in a file name? [closed]

This is a somewhat subjective question, and not very important in the big scheme of things, but something that yet annoys me regularly. There seems to be no self-evident way to put a timestamp in a file name.

Objective issue is that timestamps in file names should be sortable. But .NET sortable date formats like "s" ("yyyy-MM-ddTHH:mm:ss") and "u" ("yyyy-MM-dd HH:mm:ssZ") are not valid in file names because of ':' characters.

Other thing is that you should easily see if universal or local time is used. Practically, users seem to prefer local time to universal time.

I have mostly ended up using ISO 8601 with basic time format:

  • Local time format string "yyyy-MM-ddTHHmmsszz"
  • UTC format string "yyyy-MM-ddTHHmmssZ"

In these formats my current local time would be "2009-08-08T151800+03" and UTC "2009-08-08T121800Z"

You can also autodetect the DateTime.Kind with "K" and use "yyyy-MM-ddTHHmmssK", but then you'll have to replace the ':' characters.

Any other suggestions?

Edit: A few notes so far:

local time + time zone format "yyyy-MM-ddTHHmmsszz" is no longer sortable if multiple time zones are involved. In most cases it would make sense to drop the time zone info if it is redundant, and use UTC otherwise.

Another thing is that UTC should always be marked with 'Z', 'GMT' or 'UTC' to prevent guesswork and mistakes.

Julian dates and other stardates are cool because date arithmetic with the gregorian calendar is braindead.

like image 896
mika Avatar asked Aug 08 '09 12:08

mika


People also ask

How do I format the date in a file name?

If the date is included, write this in numbers: YYYY-MM-DD. For example, use “2017-01-10” rather than “January_10th”. If numbering files, consider how many potential files are needed and use the appropriate number of leading zeros: 001, 002, etc., will order files up to 999.

When using dates create filenames which is the best format to use?

When creating file names with dates, I like to use the YYYY-MM-DD format, making sure to use two digits for both month and day, even if you would typically use only one digit when writing it out.

What's the best date format?

The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD.


1 Answers

I use this:

My-File--2009-12-31--23-59-59.txt 
  • No spaces
  • Double dashes to separate the pieces, making each piece easy to see
  • Only one punctuation character (dash) making it easy to type
  • No timezone because for me I'm always working in my local timezone; if I needed one I'd go with UTC and append "--UTC" after the time.
like image 186
RichieHindle Avatar answered Sep 27 '22 20:09

RichieHindle