You are here

function date_format_date in Date 5.2

Same name and namespace in other branches
  1. 5 date.inc \date_format_date()
  2. 6.2 date_api.module \date_format_date()
  3. 6 date_api.module \date_format_date()
  4. 7.3 date_api/date_api.module \date_format_date()
  5. 7 date_api/date_api.module \date_format_date()
  6. 7.2 date_api/date_api.module \date_format_date()

Reworked from Drupal's format_date function to handle pre-1970 and post-2038 dates and accept a date object instead of a timestamp as input.

Translates formatted date results, unlike PHP function date_format().

Parameters

$oject: A date object, could be created by date_make_date().

$type: The format to use. Can be "small", "medium" or "large" for the preconfigured date formats. If "custom" is specified, then $format is required as well.

$format: A PHP date format string as required by date(). A backslash should be used before a character to avoid interpreting the character as part of a date format.

Return value

A translated date string in the requested format.

11 calls to date_format_date()
date_formatter_process in date/date.module
Helper function for creating formatted date arrays from a formatter.
date_format_options in ./date_api.module
Store personalized format options for each user.
date_repeat_rrule_description in date_repeat/date_repeat.module
Build a description of an iCal rule.
date_sql_handler::sql_where_date in ./date_api_sql.inc
Create a where clause to compare a complete date field to a complete date value.
date_widget_settings_form in date/date_admin.inc

... See full list

File

./date_api.module, line 586
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_format_date($object, $type = 'medium', $format = '') {
  if (empty($object)) {
    return '';
  }
  switch ($type) {
    case 'small':
      $format = variable_get('date_format_short', 'm/d/Y - H:i');
      break;
    case 'large':
      $format = variable_get('date_format_long', 'l, F j, Y - H:i');
      break;
    case 'custom':
      $format = $format;
      break;
    case 'medium':
    default:
      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
  }
  return date_t(date_format($object, $format));
}