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 -
    '#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';


charlie-s’s picture

I'm also having this issue. The README.txt in date_popup clearly states that 'a' should work:

The time selector will add AM/PM if 'a' is in the format string.

Is there a working example of this anywhere?

dubcanada’s picture

The date_popup seems to require 'Y-m-d H:i' as the #default_value format, but the #date_format will alter the #default_value


'#date_format' => 'Y-m-d h:i A',
'#default_value' => date('Y-m-d H:i', $timestamp)

Will result in

Y-m-d h:i A showing to the end user.