0

I'm using the Form API Date controls for my form, and I am wondering if there is a way to zero pad the month and day values in the HTML select elements for values less than 10 at declaration time. I am using the following render array declarations in the page callback function.

$form = array();

$form['date_from'] = array(
    '#title' => t('Date From'),
    '#type' => 'date',
);

$form['date_to'] = array(
    '#title' => t('Date To'),
    '#type' => 'date',
);

Which displays on the page as:

enter image description here

And creates the select element values (without zero padding):

enter image description here

1 Answer 1

0

I think you can use #date_format

  $format = 'm d Y';
  $form['date_from'] = array(
     '#type' => 'date',
     '#title' => t('select a date'),
     '#date_format' => $format,
   );

More values: http://php.net/manual/en/function.date.php

Your Answer

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

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