Code snippets for symfony 1.x


Refine Tags

Snippets tagged "i18n date"

Get a date from a culture dependent source

In an i18n application, if your template uses the input_date_tag() helper, the format of the date sent to the submit action will depend on the user culture. But then, how can you handle this date to, say, store it in a database in a culture independent format?

The answer lies in the sfI18N class:

$date= sfContext::getInstance()->getRequest()->getParameter('birth_date');
$user_culture = sfContext::getInstance()->getUser()->getCulture();
list($d, $m, $y) = sfI18N::getDateForCulture(

Now you have the day, month and year of the date in the $d, $m and $y variables, and you can do whatever you want with them.

If you use a Propel date setter, you can even call it directly with:


The same applies for the sfI18N::getTimestampForCulture() method.

by Francois Zaninotto on 2006-06-23, tagged culture  date  i18n