Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 3
    Underscore is a weird character. It is preferred to use ISO-8601 like $(date +%FT%T) which will give 2016-04-25T10:30:00. Commented Mar 9, 2017 at 10:29
  • 1
    @hschou Thanks for pointing out the lack of ISO-8601. I was in a bit of a rush when I originally wrote this answer, so I answered specifically to what the question asked ("The date time format can be anything sensible with underscores."). Also, colons are illegal characters for filenames on Windows, if OS interoperability was a concern. In that case, you would omit the colons, which ISO-8601 allows. I'll try to edit my answer to cover these cases. Commented Mar 10, 2017 at 15:51
  • 1
    Nice answer. I'd also point out that using 12 hour format is a bad idea in that file names wouldn't sort the same in chronological and lexical orders. (10pm would sort before 11am is ls output for instance), not to mention the cultural confusions for 12am vs 12pm. Commented Mar 10, 2017 at 17:44
  • @StéphaneChazelas I'll edit in a note about the sorting issues of the 12 hour time format. I'm not aware of any cultural confusions regarding 12am vs. 12pm, just general confusion. Care to enlighten me with an example? Regarding your edit with quotes, it actually works fine for me in GNU Bash 4.2.25(1)-release with or without those quotes. Commented Mar 10, 2017 at 18:18
  • @Ryan You are right about Windows and colon. I think the most common format on Windows is YYYYmmdd_HHMMSS (yes, they use one underscore). If in doubt then consult xkcd.com/1179 Commented Mar 11, 2017 at 16:55