Reorganized Date Formatting Options

I posted a Feature Request for this to be changed in the EE Docs, but I know the EE folks are busy so I’m posting a version of the EE date formatting options, reorganized by output rather than alphabetically by letter.

 

Seconds:

  • %s - seconds (“00” to “59”)
  • %U - seconds since the epoch


Minutes:

  • %i - minutes (“00” to “59”)


Hours:

  • %g - hour, 12-hour format without leading zeros (“1” to “12”)
  • %G - hour, 24-hour format without leading zeros (“0” to “23”)
  • %h - hour, 12-hour format (“01” to “12”)
  • %H - hour, 24-hour format (“00” to “23”)


AM/PM:

  • %a - “am” or “pm”
  • %A - “AM” or “PM”


Day:

  • %d - day of the month, 2 digits with leading zeros (“01” to “31”)
  • %D - day of the week, textual, 3 letters (“Fri”)
  • %j - day of the month without leading zeros (“1” to “31”)
  • %l (lowercase ‘L’) - day of the week, textual, long (“Friday”)
  • %w - day of the week, numeric - “0” (Sunday) to “6” (Saturday)
  • %z - day of the year (“0” to “365”)
  • %S - English ordinal suffix, 2 characters; (“th”, “nd”)


Week:

  • %W - ISO-8601 week number of year, weeks starting on Monday (“42”: the 42nd week in the year)


Month:

  • %M - month, textual, 3 letters (“Jan”)
  • %F - month, textual, long (“January”)
  • %n - month without leading zeros (“1” to “12”)
  • %m - month with leading zeros (“01” to “12”)
  • %t - number of days in the given month (“28” to “31”)


Year:

  • %y - year, 2 digits (“99”)
  • %Y - year, 4 digits (“1999”)
  • %L - boolean for whether it is a leap year (“0” or “1”)


Other

  • %B - Swatch Internet time
  • %I (capital i) - “1” if Daylight Saving Time, “0” otherwise.
  • %T - Time zone setting of this machine (“MDT”)
  • %Z - time zone offset in seconds (”-43200” to “43200”). The offset for time zones west of UTC is always negative, and for those east of UTC is always positive.
  • %Q - local server time zone offset, in hours and seconds, against GMT (e.g. “+06:00”)
  • %r - RFC 822 formatting (“Thu, 21 Dec 2000 16:01:07 +0200”)


Common Formats
12/12/09

{entry_date format="%m/%d/%y"

January 10, 2010

{entry_date format="%F %j, %Y"

Wednesday, July 16th, 2008

{entry_date format="%l, %F %j%S, %Y"

01/11 at 01:31 PM

{entry_date format='%m/%d'} at {entry_date format='%h:%i %A'

 

 

Category Navigation

Next Entry >>

 

Previous Comments

Picture of Jesse Schutt

by Jesse Schutt

Date: Monday, January 11th, 2010
Comment: #1

Hey Mike,

You could really sweeten up this page if you compiled a bunch of the regulars like 1/11/10 or January 1, 2010 in the date formats.  Or I could do it and quit being lazy!

Mike Boyink

by Mike Boyink (Author)

Date: Tuesday, January 12th, 2010
Comment: #2

Done!

Picture of Jesse Schutt

by Jesse Schutt

Date: Tuesday, January 12th, 2010
Comment: #3

.... bookmarked ... Thanks!

Picture of Jordan henderson

by Jordan henderson

Date: Tuesday, January 26th, 2010
Comment: #4

Great post - thank you for the help!

Picture of Adam Wiggall

by Adam Wiggall

Date: Tuesday, February 16th, 2010
Comment: #5

Mike

You may want to add %m to the month entries to get the day of the month with leading zero, e.g. 01, 02 etc…

Mike Boyink

by Mike Boyink (Author)

Date: Tuesday, February 16th, 2010
Comment: #6

Added - thanks for the catch!

Picture of Susan McDonough

by Susan McDonough

Date: Tuesday, June 15th, 2010
Comment: #7

I have a bilingual site. I want the date to display in french here: http://www.engineering.uottawa.ca/fr/S=fce808bd1934498204c7c6ddbed0bac53bec2f21/events_calendar/event_archives/

But in English here:
http://www.engineering.uottawa.ca/en/S=fce808bd1934498204c7c6ddbed0bac53bec2f21/events_calendar/event_archives/

this is the code:
<h4 class=“date”>{if country_code !=“en”}{entry_date format=”%d %M %Y”}{if:else}{entry_date format=”%M %d, %Y”}{/if}</h4>
Cheers

Picture of John St-Amand

by John St-Amand

Date: Wednesday, June 16th, 2010
Comment: #8

Is there a simple way to just display the recorded localized server time zone rather than the offset?  Is there a formatting variable for that?  For example, to display current time with EST next to it automatically based on Eastern being the selected time zone in the system preferences of EE? I could hard code it into the display template, but a dynamic setting taking its cue from that system preferences seems like a smarter play if it’s possible. Thanks Mike! I learn something new every time I visit your site.

Mike Boyink

by Mike Boyink (Author)

Date: Wednesday, June 16th, 2010
Comment: #9

Don’t know—If it’s not mentioned in the docs then I ask in the forums.

Picture of Biko

by Biko

Date: Tuesday, November 9th, 2010
Comment: #10

Could anyone explain it to me how can I add or substract time, and do some comparsion?

Mean on:
if entry_date < (current_time - 2 hour)
sometnihng
if:else
something else

Thanks Mike :)

Picture of Cavell Blood

by Cavell Blood

Date: Thursday, March 24th, 2011
Comment: #11

@Biko, I think you’ll have to get the number of seconds in 2 hours or whatever amount of time that you want to subtract. For example 2 hours is equal to 172800 seconds. Try this:

{if {entry_date} < ({current_time} - 172800)}
your code here
{if:else}
your code here
{/if}

Hope that helps!

Add Your Comment

Commenting is not available in this channel entry.

Unless otherwise stated all content is © Michael Boyink of Train-ee.com & Boyink Interactive. Please don't steal - I've got kids to feed...

dy>