Jun 11, 2010

Posted by in Joomla | 1 comment

How to format dates in Joomla

Some times we need to show a formatted date with better readable option rather than showing it in yyyy-mm-dd format (the default format gets stored in db).

May be you are creating a news and events module or a component where you want to show the date to the user in a better formatted way, ex – may be like 20th Feb 2010 instead of 2010-02-20.

We can certainly do this by writting our own function and can use it where we want, but as Joomla has a built in class and code written for it, why write it again? So, here is how we can use it.

Joomla has the build in JDate class which we can use to format the given date.

//import the JDate library

//create an instance of JDate class by providing date as param
$jdate = new JDate('2010-02-20');

//echo the date in given format.
echo $jdate->toFormat('%d %b %Y');

Output will be 20 Feb 2010

For a list of formats please visit http://in2.php.net/strftime

  1. Hi,

    This is some what new for me…

    Good to known this for me…


Leave a Reply