Change Default Drupal Date Display with PHP

posted by Ishmael Sanchez on Mar 30, 2009

Once you install your Drupal site, you will need to perform some basic configuration. One of the first things to do is to set the date and time. By default, Drupal provides a pretty long format to display the date. This date format is used by default in the node.tpl.php and output in the $submitted variable.

You can update the default date display using PHP. First you need to go to the Drupal date and time admin page. To get to that admin page, type the following into your web browser: http://mysite.com/admin/settings/date-time.

This example assumes you have clean URL's enabled, otherwise you would type: http://mysite.com/?q=admin/settings/date-time. The page should look something like the image below:

Drupal Date and Time Admin Screen
Default Drupal date and Time Admin Screen

You can configure the time as you like. Next, scroll down to the formatting section. Under "short date format" text, select the drop down menu and pick "custom format".

Drupal Custom Date
Select Custom Date

From here, a text field will appear where you define your custom date using the PHP date function. You can see I typed M d, Y. Notice Drupal shows an example of how the date will appear in the text under the text field. Rinse and repeat for the medium and long date format.

Drupal Custom Date
Drupal Custom Date Display

Resources

Tags:

Ishmael Sanchez