CakePHP default dateTime()

In the FormHelper class of Cake 1.2 there’s a method for generating fields for a datetime. It is not documented very well but you can pass a timestamp into the “selected” parameter and it will default the dropdowns to the date and time of that timestamp.

For instance, if you make this call:

echo $form->dateTime('GiftCard.expire','MDY','NONE',strtotime('+1 month'));

it will result in three select fields; Month, Day, Year; and they will be defaulted to one month from today. strtotime(’+1 month’) returns a timestamp corresponding one month from today.


About this entry