![]() |
|
Snippets |
|
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( $date, $user_culture );
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:
$person->setBirthDate("$y-$m-$d");
The same applies for the sfI18N::getTimestampForCulture() method.