Hi,

When you have a date field as one of your components, is there a way to change the default order of 'Month-Day-Year' to: 'Day-Month-Year'?

Thanks,

Mark

Comments

quicksketch’s picture

Category: feature » support
Status: Active » Fixed

Yes, just change the order of your "small" format in the site wide date settings. Webform (as well as Drupal core) use the small format when ordering #type = date elements.

dmatthey’s picture

Doesn't work for me. Also tried to define a custom date format "d/m/Y" and assigned it to the short date format. Then I still get values of type m/d/Y in my webform emails.

An other idea?

quicksketch’s picture

Sorry it's the "short" format, not "small". See this function in Drupal core for the logic: http://api.drupal.org/api/drupal/includes--form.inc/function/expand_date/6

markwsimon’s picture

Many thanks! Mark

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

commanderflash’s picture

I am having the same issue and I have updated the Short date format. It appears to ignore the Drupal system date settings.

quicksketch’s picture

hello2robi’s picture

Issue summary: View changes

Use the function bellow in you template.php file and replace 'mytheme' with your theme name to override webform date format ...

/**
 * Reorder the dates to d/m/y not m/d/y
 */
function mytheme_webform_date($variables) {
  $element = $variables['element'];

  //Save the data from the array into variables.
  $day = $element['day'];
  $month = $element['month'];
  $year = $element['year'];

  //Remove these keys from the array.
  unset($element['day']);
  unset($element['month']);
  unset($element['year']);

  //Re-add the data to the array in the correct order.
  $element['day'] = $day;
  $element['month'] = $month;
  $element['year'] = $year;

  $element['year']['#attributes']['class'] = array('year');
  $element['month']['#attributes']['class'] = array('month');
  $element['day']['#attributes']['class'] = array('day');

  // Add error classes to all items within the element.
  if (form_get_error($element)) {
    $element['year']['#attributes']['class'][] = 'error';
    $element['month']['#attributes']['class'][] = 'error';
    $element['day']['#attributes']['class'][] = 'error';
  }

  $class = array('webform-container-inline');

  // Add the JavaScript calendar if available (provided by Date module package).
  if (!empty($element['#datepicker'])) {
    $class[] = 'webform-datepicker';
    $calendar_class = array('webform-calendar');
    if ($element['#start_date']) {
      $calendar_class[] = 'webform-calendar-start-' . $element['#start_date'];
    }
    if ($element['#end_date']) {
      $calendar_class[] = 'webform-calendar-end-' . $element['#end_date'];
    }
    $calendar_class[] ='webform-calendar-day-' . variable_get('date_first_day', 0);

    $calendar_options = array(
      'component' => $element['#webform_component'],
      'calendar_classes' => $calendar_class
    );
    $calendar = theme('webform_calendar', $calendar_options);
  }

  $output = '';
  $output .= '<div class="' . implode(' ', $class) . '">';
  $output .= drupal_render_children($element);
  $output .= isset($calendar) ? $calendar : '';
  $output .= '</div>';

  return $output;
}
ccarnnia’s picture

Hard coding "short" as the default value of D7 webform date field worked for me.