How to save a custom attribute that is a type == date

Permalink 1 user found helpful
When I try to save a date/time attribute by writing:

$date_key = CollectionAttributeKey::getByHandle('event_date_time');
$date_key->saveAttributeForm($p);


$p is the page. $p works when I save other attributes (i.e. text) just not the date attribute.
It doesn't seem to be saving the date?

For example, I have a text box called "event_location" that saves successfully:

$location_key = CollectionAttributeKey::getByHandle('event_location');
$location_key->saveAttributeForm($p);


I also tried:

$date_key = CollectionAttributeKey::getByHandle('event_date_time');
$date_key->setAttribute($p, $date_key);

 
Mainio replied on at Permalink Best Answer Reply
Mainio
You should do it other way around as far as I know:
$p->setAttribute('event_date_time', '2012-05-08 10:10:10');
nicolechung replied on at Permalink Reply
I think also it might have been the way I was rendering the date in my form.

I was using

echo $df->datetime('event_date_time', $event_date);


but really I should have used:

echo $key_date->render('form', $date_value, true)