You are here

function date_granularity_format in Date 7

Same name and namespace in other branches
  1. 6.2 date_api.module \date_granularity_format()
  2. 7.3 date_api/date_api.module \date_granularity_format()
  3. 7.2 date_api/date_api.module \date_granularity_format()

Construct an appropriate DATETIME format string for the granularity of an item.

File

date_api/date_api.module, line 1081
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_granularity_format($granularity) {
  if (is_array($granularity)) {
    $granularity = date_granularity_precision($granularity);
  }
  $format = 'Y-m-d H:i:s';
  switch ($granularity) {
    case 'year':
      return substr($format, 0, 1);
    case 'month':
      return substr($format, 0, 3);
    case 'day':
      return substr($format, 0, 5);
    case 'hour':
      return substr($format, 0, 7);
    case 'minute':
      return substr($format, 0, 9);
    default:
      return $format;
  }
}