On Fri, Apr 10, 2009 at 4:20 PM, PHPScriptor <[email protected]> wrote:
>
> Ok, never understood how this worked, so a good explanation would be nice :-)
>
> in my form, my date is: dd-mm-yyyy
>
> $date[] = self::createElement('text', 'mydate')
>        ->addValidator('Date', 'YYYY-MM-DD', array('DD-MM-YYYY'))
>
> but for inputting it in my mysql the format needs to be yyyy-mm-dd.
>
> What I do know to convert:
>
> $formData = $this->_request->getPost();
> $date        = explode("-",formData );
> $formData['mydate'] = $date[2]."-".$date[1]."-".$date[0];
>
>
> 1. Is there a way to do this e.g. with Zend Date?

Try something like (I haven't doublechecked):

$date = new Zend_Date($this->_request->getPost('mydate'), 'DD-MM-YYYY');
$mysql_date = sprintf('%s-%s-%s', $date->get('YEAR'),
$date->get('MONTH'), $date->get('DAY'));

I'd add the conversion part to the model.

Till

Reply via email to