29 Aprili 2003

Movable Type dates

I should not have to write this post. It’s just that the documentation for dates in Movable Type is—okay, it’s just plain organized wrong. I hope this will be fixed in an upcoming release.

Date- and time-related placeholders (<MTEntryDate>, <MTCommentDate>, <MTCommentPreviewDate>, <MTArchiveDate>, <MTArchiveDateEnd>, <MTPingDate>, and <MTDate>) all have a format attribute whose value is a concatenation of incomprehensible codes starting with % that represent various parts of a date and time.

If you’re lucky, you can use the two fully-elaborated codes and save yourself a lot of pain. %x gives you the date, in the form “September 6, 2002”. %X gives you the time, in the form “4:31 PM”. If these work for you, for heaven’s sake use them!

Otherwise, read on…

Movable Type’s documentation organizes all these codes alphabetically by code, which is great for geeks, not so good for everybody else. Here’s the list organized by unit of time, small units first, the way $DEITY intended:

Second: %S
Minute: %M
Hour:
  • 24-hour, two digits: %k
  • 12-hour, always two digits: %I
  • 12-hour, one or two digits: %l
AM or PM: %p
Weekday name:
  • In full: %A
  • Abbreviated: %a
Day of month:
  • Always two digits: %d
  • One or two digits: %e
Day of year: %j
Month:
  • In full: %B
  • Abbreviated: %b
Year:
  • Two-digit: %y
  • Four-digit: %Y

Putting it all together: To get a date header like Caveat Lector’s—well, first you have to hack Movable Type itself to produce Latin month and weekday names. Not recommended, but I’ll tell you how if you ask.

But let’s pretend that I am a normal English-language blogger using English-language dates. What I’m using is the full weekday name, a comma, the one- or two-digit day of the month, the full month name, and the four-digit year. That works out to <MTEntryDate format="%A, %e %B %Y">. Note that you have to include any punctuation (such as my comma) and spaces you want.

Whereas the weekly-archive links in my blogroll use the abbreviated month, the one- or two-digit day of the month, and the four-digit year. (And the month names are in English, but you don’t need to know how I did that.) That’s <MTArchiveDate format="%b %e %Y">.

See? Not so bad. Okay, okay, bad but manageable.