Date Variable Formatting

NOTE: Please note that these examples are to show how the date formatting codes are used in the format parameter that is used in a number of different ExpressionEngine variables.

Many of the tags you'll use in your templates contain variables designed to display dates and times.  These variables can be formatted so that the date appears in a manner you wish. Here is an example of a typical "date type" tag:

{date format="%F %d %Y"}

The "format" parameter enables you to format the date using the Date Formatting Codes listed below. Each code letter is always preceded by a percent sign.  The example above would be rendered like this:

January 15 2006

You are allowed to use any character you want within the format parameter, except a percent sign. For example, this:

{current_time format="%D, %F %d, %Y - %g:%i:%s"}

Would be rendered like this:

Mon, January 15, 2006 - 10:23:45

Date Formatting Codes

Available date formatting codes:

Date Formatting Constants

You may also use the pre-defined Date Formatting Constants listed below for easy access to some standard format strings. For example, this:

{current_time format="{DATE_ATOM}"}

Would be rendered like this:

2006-01-15T20:23:45-06:00

Available pre-defined formatting strings are described in the table below.

Date Formatting Constants
Variable Equivalent Sample Rendering
{DATE_ATOM} %Y-%m-%dT%H:%i:%s%Q 2006-10-16T08:19:39-06:00
{DATE_COOKIE} %l, %d-%M-%y %H:%i:%s UTC Monday, 16-Oct-06 08:19:39 UTC
{DATE_ISO8601} %Y-%m-%dT%H:%i:%s%O 2006-10-16T08:19:39-0500
{DATE_RFC822} %D, %d %M %y %H:%i:%s %O Mon, 16 Oct 06 08:19:39 -0500
{DATE_RFC850} %l, %d-%M-%y %H:%m:%i UTC Monday, 16-Oct-06 08:10:19 UTC
{DATE_RFC1036} %D, %d %M %y %H:%i:%s %O Mon, 16 Oct 06 08:19:39 -0500
{DATE_RFC1123} %D, %d %M %Y %H:%i:%s %O Mon, 16 Oct 2006 08:19:39 -0500
{DATE_RFC2822} %D, %d %M %Y %H:%i:%s %O Mon, 16 Oct 2006 08:19:39 -0500
{DATE_RSS} %D, %d %M %Y %H:%i:%s %O Mon, 16 Oct 2006 08:19:39 -0500
{DATE_W3C} %Y-%m-%dT%H:%i:%s%Q 2006-10-16T08:19:39-06:00

Top of Page

User Contributed Notes

Posted by: MediaGirl Inc. on 27 July 2007 6:57pm
MediaGirl Inc.'s avatar

TIP: To keep my copyright date current in my footers, I use {current_time format=”%Y”} to show the current year.

Posted by: georges on 15 July 2007 6:14pm
georges's avatar

This formatting works on custom datetime fields, not just the built in datetime variables that are available through EE.

You must have an ExpressionEngine license and have attained a forum rank of "Lab Assistant" (100 posts) to contribute notes to the User Guide