Friday, November 16, 2007

Smarty format date

How to format date in Smarty



When you extract a date field from database, it is in the format yyyy-mm-dd. But maybe you want to list it other format, for example dd-mm-yyyy. You can retrieve this format directly from database, usign MySQL function DATE_FORMAT, or if you are using Smarty you can use date_format function.

Here is an example of Smarty date formatting:

{$smarty.now|date_format:"%d:%m:%Y"}

This will format current time, in dd-mm-yyyy format.
You can find all date conversions on smarty website.


Formatting dates using Smarty

2 comments:

Community Little Book said...

hey, thanks much for the tip, was looking for something just like this for my site.

Anonymous said...

here is a good website for helping format dates using the date_format function mysqlformatdate.com