Handling Joomla! dates

For the longest time, I’ve had troubles parsing the Joomla! date. It is normally found in this format: “Y-m-d H:i:s” which translates to: year-month-day hour:minute:second  or  2009-01-29 22:05:15
Many times before I have parsed this date to change to a format that is more user friendly, but it had never been a one liner.

Previously I tried these two methods:

$date = date_parse($row->created);
$date = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
echo date("M d, 'y", $date);

or

$date = new JDate($row->created);
echo date("M d, 'y", $date->toUnix()); //toFormat only works half of the time.

Today I decided to try something new because those two options are ridiculous and unnecessary. I came up with this:

echo date("M d, 'y", strtotime($row->created));

Nice and short :)

Hope you find this useful.

The Core Team
Editorial Staff Members at 'corePHP'
Editorial staff for the Core Technology Blog for 'corePHP' - news, views insights and advice for e-commerce, marketing technology , web design and development.

One thought on “Handling Joomla! dates

  1. Pete

    Nice,

    echo date(“M d, ‘y”, strtotime($row->created));

    works like a charm and is way cleaner,

    Thanks

    Pete

Comments are closed.