1

How can I find if a form has date/time field or not and if it has, how can I detect what is date format for it?

1

For the Date popup selector, the #date_format element in the form element. For example:

    //The date field has the format of "d-m-Y"
    $form['date_field'] = array(
      '#type' => 'date_select',
      '#title' => t('My Date'),
      '#date_format' => 'd-m-Y',
      '#date_label_position' => 'within',
      '#date_year_range' => '0:+1',
      '#description' => t('This is a test date picker'),
      '#default_value' => date('Y-m-d H:i:s'),
    );

There's an D6 documentation page on d.o, but it's still valid for D7 last I looked.

1
  • this code works when you want to add a new field to a form. I mean when in form_alter between available fields, how we can detect which fields are datetime and how we can detect what is date format for each of them. indeed I want to manipulate datetime fields in output render. – Mehrdad201 Oct 5 '15 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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