function hook_date_format_types

Define additional date types.

Next to the 'long', 'medium' and 'short' date types defined in core, any module can define additional types that can be used when displaying dates, by implementing this hook. A date type is basically just a name for a date format.

Date types are used in the administration interface: a user can assign date format types defined in hook_date_formats() to date types defined in this hook. Once a format has been assigned by a user, the machine name of a type can be used in the format_date() function to format a date using the chosen formatting.

To define a date type in a module and make sure a format has been assigned to it, without requiring a user to visit the administrative interface, use

variable_set('date_format_' . $type, $format);

where $type is the machine-readable name defined here, and $format is a PHP date format string.

To avoid namespace collisions with date types defined by other modules, it is recommended that each date type starts with the module name. A date type can consist of letters, numbers and underscores.

Return value

An array of date types where the keys are the machine-readable names and the values are the human-readable labels.

See also

hook_date_formats()

format_date()

Related topics

1 function implements hook_date_format_types()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

system_date_format_types in drupal/modules/system/system.module
Implements hook_date_format_types().
1 invocation of hook_date_format_types()
_system_date_format_types_build in drupal/modules/system/system.module
Builds and returns information about available date types.

File

drupal/modules/system/system.api.php, line 4141
Hooks provided by Drupal core and the System module.

Code

function hook_date_format_types() {

  // Define the core date format types.
  return array(
    'long' => t('Long'),
    'medium' => t('Medium'),
    'short' => t('Short'),
  );
}