views:

423

answers:

1

Hi,
I'm working on a Zend Framework (v1.7) application that calls for a few forms that users need to enter dates on.

The user is prompted to enter dates in the dd/mm/yyyy format, but the MySQL database wants the dates to be presented in yyyy-mm-dd format. Therefore, i'm having to do the following:

Loading the form

  1. Grab the data from the database
  2. Re-format the date fields using Zend_Date into the dd/mm/yyyy format

Saving the form

  1. Validate the date fields using Zend_Validate
  2. Check if the date field is present. If so, re-format it into the yyyy-mm-dd format. If not, set it to NULL
  3. Save to the database

There must be an easier way to do this :-S

Can anyone suggest one?

Cheers,
Matt

+2  A: 

You can skip the reformatting if you use the according sql functions like DATE_FORMAT() and STR_TO_DATE() in MySql. The rest looks ok to me.

soulmerge
Thanks for your reply - i'll give that a try.
fistameeny