I am using the following code to display a date popup in my drupal 6 custom module.

 $form['intelligence']['start_date'] = array(
    '#type' => 'date_popup',
    '#date_year_range' => '-100:+0',
    '#prefix' => '<div class="start_datefield_div"> ', 
    '#date_format' => 'Y-M-d',
    '#default_value' => date('Y-M-d',  time()),

But I am getting default date blank.

I have gone through Date popup form field doesn't show the default value correctly and string espected but array given in custom pop_date field #default_value , but no success .

Can anybody tell, what the issue is with this code? Actually I need $_POST['start_date'] as the default value. But for testing purpose I put date('Y-M-d', time())

  • 1
    Look at the examples on the other questions a bit more closely: '#default_value' => date('Y-m-d', $date). Notice the lower case 'm'; it's counter-intuitive but date_popup is expecting the default value in a very specific format, regardless of the format you've chosen for display
    – Clive
    Apr 26 '13 at 12:12
  • I changed the code to $form['intelligence']['start_date'] = array( '#type' => 'date_popup', '#date_year_range' => '-100:+0', '#description'=>'Start', '#prefix' => '<div class="start_datefield_div"> ', '#date_format' => 'Y-m-d', '#default_value' => date('Y-m-d', time()), '#suffix'=>'</div>' );,but still it is blank
    – user7282
    Apr 26 '13 at 12:28
  • Default value should be in the format "Y-m-d H:i:s", regardless of what you use as your display format. Oct 17 '14 at 11:46

Your Answer

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

Browse other questions tagged or ask your own question.