2

I would like to pass a date in the format 2013-04-23 00:00:00 as a #default_value into a form builder function:

$form['date'] = array(
    '#title' => t('Date'),
    '#type' => 'date',
    '#default_value' => $my-array['date'],
);

...but the form renders dates in a three column drop-down widget (which I want to keep). How do I reformat my date and/or form builder function so that my three drop-downs display 23 Apr 2013? At present, they display 02 Feb 1900.

Thanks

Solution

See @tostinni's answer for half of the soluion. This is the second half:

$timestamp = strtotime($my-array['date']);
$day = date('d', $timestamp);
$month = date('n', $timestamp);
$year =  date('Y', $timestamp);

1 Answer 1

0

The Form API documentation will help you figure this out, you'll have to pass an array with the year, month and day keys like this:

$form['date'] = array(
    '#title' => t('Date'),
    '#type' => 'date',
    '#default_value' => array('year' => 2013, 'month' => 4, 'day' => 23),
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.