Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Using the following code:
$date_format = 'Y-m-d h:i A';
$today = date($date_format);
if (isset($blogentity->live_on_date)) {
$the_date = date($date_format, $blogentity->live_on_date);
}
else {
$the_date = $today;
}
$form['live_on_date'] = array(
'#type' => 'date_popup',
'#title' => t('Date this blog goes live'),
'#default_value' => $the_date,
'#date_format' => $date_format, // Uses the PHP date() format - http://php.net/manual/en/function.date.php
'#date_increment' => 5,
'#date_year_range' => '-3:+3', // Limits the year range to the next two upcoming years
'#required' => FALSE,
'#weight' => 130,
does not work for me. Neither the date nor time display in their popup fields. Same thing for:
$date_format = 'Y-m-d h:iA';
$date_format = 'Y-m-d h:ia';
$date_format = 'Y-m-d h:i a';
$date_format = 'Y-m-d h:i A';
However, military time works just fine:
$date_format = 'Y-m-d H:i';
Comments
Comment #1
charlie-s CreditAttribution: charlie-s commentedI'm also having this issue. The README.txt in date_popup clearly states that 'a' should work:
Is there a working example of this anywhere?
Comment #2
dubcanada CreditAttribution: dubcanada commentedThe date_popup seems to require 'Y-m-d H:i' as the #default_value format, but the #date_format will alter the #default_value
So
Will result in
Y-m-d h:i A showing to the end user.