format_date vs date_format_date drupal 7

Drupal 6/7 core:

// $datetime example "2009-12-09 11:57:16"
$timestamp = strtotime($datetime);
$my_date = format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL);

Drupal 6 with date module:

$date = date_make_date($timestamp, $timezone = NULL, $type = DATE_DATETIME, $granularity = array('year', 'month', 'day', 'hour', 'minute'));
$my_date = date_format_date($date, $type = 'medium', $format = '', $langcode = NULL);

Drupal 7 with date module:

// $datetime example "2009-12-09 11:57:16"
// Construct own format: DateTime::createFromFormat
$date = new DateObject($datetime);
$my_date = date_format_date($date, 'custom', variable_get('mycustomtype', 'maand'), $langcode = NULL);

Notice how you can't use predefined configurations directly in $type as is possible in drupal core's format_date.
Related issue: http://drupal.org/node/1343464

About

This is the company blog of
Drupal specialist Merge.nl

We are located in Breda (Netherlands) and build websites using Drupal. More about us.

Content on this blog is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.

Creative Commons License

Recent Comments

Social