Automagically generated date/time input fields normally default to the current date and time. For a couple of reasons, I had to change this to another default value. For example's sake, let's say I needed a time field to always select 1:30 pm in an add action.
Run of the mill example:
<?php
echo $form->input('start_dt');
?>
This will output 3 select boxes; one for hours, minutes, and the merdian (am/pm) with the current time pre-selected. So if it was 3:04 pm, that would be selected.
So lets change this so that 1:30 pm is always pre-selected:
<?php
echo $form->input('start_dt', array('selected' => array('hour' => '1',
'minute' => '30',
'meridian' => 'pm')
)
);
?>
That's all there is to it! Cake's automagic owns. Hope this helps someone else :)



Comments
Josh on (12.16.2008 8:35 pm) says
Søren on (2.4.2009 6:49 pm) says
Frans on (7.29.2009 3:25 pm) says
This does the trick, hope it helps... echo $form->input('PlayerProfile.date_of_birth',array('dateFormat'=>'YMD','timeFormat'=>'NONE','selected'=>strtotime('2000-01-01'),'minYear'=> date('Y') - 100,'maxYear' => date('Y')));Chris on (9.27.2009 5:11 am) says
Ryan on (10.14.2009 5:28 pm) says
John G on (3.26.2010 9:47 am) says