Drupal 7 Tutorial: How to add a Custom Date Format

By default, Drupal only offers three types of date formats. Long, Medium and Short.

1

In this tutorial we are going to add our own: 30Jul14

First, go to

admin/config/regional/date-time/formats

Click Add Format

Under the ‘Format String’ entry box, click the ‘Php Manual’ link where it says ‘see the PHP Manual for available options’ (make sure to open it in another window to avoid losing your current page.)

2

It will lead you to http://php.net/manual/en/function.date.php , the PHP page for characters recognized in php’s format parameter string. Look for the format specific to what you want, which in my case is:

d – Day of the month, 2 digits with leading zeros – 01 to 31
M – A short textual representation of a month, three letters – Jan through Dec
y – A two digit representation of a year – Examples: 99 or 03

place that string in the ‘format string’ entry box:

3

Click Add Format, and you will now have a new format to use. But before you can use it you will need to give it a name. Click the ‘Types‘ TAB, then click ‘Add Date Type‘.

Give it a descriptive name, such as the actual result itself you want. In my case, 30jul14.

4

Save it.

You now have custom date format.

5

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.