I have a date_field Date (ISO format) as a Pop-up calendar. I would like to have it as a default value: today 10:30 In php the

strtotime("today +10 hours 30 minutes")

serves me well. Also

strtotime("today 10:30 am")

If I put it in the "Relative default value" field, the time gets not parsed. It is always the current time.




has the same effect. Bug? How to get the default date to "today 10:30 am"?

  • 1
    Are you putting "strtotime("today +10 hours 30 minutes")" or just "+10 hours 30 minutes". I'm fairly certain that the second is what you want.
    – Chance G
    Oct 5 '11 at 22:13
  • Sorry that I haven't be clear enough. With the PHP function I get the working syntax. In the Date field I put ""today 10:30 am". Not working. I will post a bug report. Oct 6 '11 at 9:03
  • Is this a custom form built with the form api or a date popup field added to an entity?
    – LSU_JBob
    Oct 10 '11 at 22:38

The best way to control the default output of form elements is through the drupal Form API.

You have two scenarios:

  1. If you created the form with the form api and have a date popup in your form, you can use the method described in this post to set the #default_format of the #default_value of the form element.
  2. If you didn't create the date popup in the form element with the form api, meaning you added it as a field to an entity through site configuration, you can still make a small custom module solution. Make a custom module and implement hook_form_alter, find the field in question and set the #default_value using the method mentioned in #1

It's been fixed, YAY! http://drupal.org/node/1302212


This will surely work.

$form['date'] = array(
  '#default_value' =>date('Y-m-d'),
  '#date_type' => DATE_DATETIME,
  '#date_timezone' => date_default_timezone(),
  '#date_format' => 'm/d/Y',
  '#prefix' => '<td>',
  '#suffix' => '</td></tr></table>',

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.