Quick tip: Expression Engine Microformatted date

Feature image

I’m rebuilding SuperGeekery behind the scenes. Along the way, I will try to post little tidbits I think might be helpful along the way.

I’ve spent the past 10 minutes formatting the dates for entries using microformats. That means wrapping the human-readable date that is displayed on a web site inside a <time> tag that is machine-readable. Here’s how you do that in Expression Engine.

<div class="date">
	<time datetime="{entry_date format='%Y-%m-%dT%H:%i:%s%O'}">
		{entry_date format=' %M %j '}
</div><!-- .date -->

This code generates a machine-readable date of “2010-01-12T21:45:57-0500”, for example,  which is invisible to a human reading the web page. The person reading the page sees “Jan 12” only.

One thing I’m not clear on is the time zone offset from GMT, the last bit of the machine-readable date. I’ve seen it use the offset with a colon, basically -5:00 instead of -500 mentioned. It looks like that would be accomplished by using {entry_date format=’%Y-%m-%dT%H:%i:%s%P’}, but it doesn’t seem to work on my development environment. Hmmmm.

Comments on this post.

This is very useful. Especially so as a snippet, you can call it at any time by something like {sn_mf-date}

Thanks for sharing.

By Kent Web Design on Jul 14 2012

Leave Your Comment:





your comment:

Remember my personal information

Notify me of follow-up comments?