Skip to content

Instantly share code, notes, and snippets.

@jonhattan
Created December 13, 2013 10:37
Show Gist options
  • Save jonhattan/7942525 to your computer and use it in GitHub Desktop.
Save jonhattan/7942525 to your computer and use it in GitHub Desktop.
Snippet to create date formats in Drupal.
<?php
// Array of type => format.
$formats = array(
'day_monthname_year' => 'j \d\e F \d\e Y',
'weekday_day_monthname_year' => 'l j \d\e F \d\e Y',
);
$query_types = db_insert('date_format_type')->fields(array('type', 'title'));
$query_formats = db_insert('date_formats')->fields(array('format', 'type'));
foreach ($formats as $type => $format) {
$query_types->values(array(
'type' => $type,
'title' => $type,
));
$query_formats->values(array(
'format' => $format,
'type' => 'custom',
));
variable_set('date_format_' . $type, $format);
}
$query_types->execute();
$query_formats->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment