The Coding Pad

Programming blog – Discussions, Tutorials, Resources

The Coding Pad header image 2

Quick Tip: MODX – Modify the date format for the TwitterX output |

July 7th, 2013 · 1 Comment · MODX, Tutorials

While working on a MODX client project I used the TwitterX snippet, which uses the new Twitter 1.1 API, to pull in the clients twitter feed to her site. The snippet comes with a default tpl chunk which you should duplicate and modify for your purposes as I have done below to format the tweet feed as you please.


<a href="[[+screen_name]]" target="_blank">[[+created_at:ago]]</a> via [[+source]]</li>

You definitely must duplicate rather than edit the default tpl, as any updates will overwrite your changes.

Anyway, my client wanted the date format for the tweets to show up as “day month date, year”. For example Sun Jul 7, 2013. I started by removing the “ago” part of the created_at placeholder. This partially got me there:


But now the date is in the format Sun Jul 07 09:24:57 +0000 2013, which is a lot more information than I want. The solution is actually pretty simple. The date format that the Twitter API spits out is the RFC822 format for feeds. How do we convert this to a different format?

The easiest way is to first convert it into a UNIX timestamp and then from the UNIX timestamp into whatever format you desire. At least this is the route I’m taking :)

In MODX, we use chained Output modifiers to accomplish our goal. We first convert the RFC822 formatted date into a UNIX timestamp using strtotime, like this:


<a href="[[+screen_name]]" target="_blank">[[+created_at:strtotime]]</a> via [[+source]]</li>

This gives us:


We then modify that to our desired format using the date modifier and our desired format, like this:


<a href="[[+screen_name]]" target="_blank">[[+created_at:strtotime:date=`%a %b %e, %Y`]]</a> via [[+source]]</li>

That gives us the desired outcome:


Hope you find this and the links below helpful.

More Reading:

If you enjoyed this post, make sure you subscribe to my RSS feed!

Related Posts

Tags: ··

One Comment so far ↓

  • Matt

    I’ve learned a lot from your posts. Thanks for posting all of the great MODx info.

    I seem to have a “love/hate” relationship with that CMS, but for the most part it’s enjoyable to work with.

Leave a Comment

Subscribe without commenting