Development

formatDateHowTo

You must first sign up to be able to contribute.

Supported formats for symfony format_date helper

(based on the sfDateFormat::format() method )

This is a date/time format helper. It is i18n aware which means that it's output is affected by the i18n setting of symfony and the current sf_user culture variable. It supports some out of the box formats but can be very flexible. The following listing is a quick reference to all the supported patterns. (It corresponds to symfony 1.2.10).

Out of the box format patterns

These formats correspond to one letter patterns. This is the list of out of the box patterns with example outputs for 2 locales (en, el)

locale: en

  • d :2010-02-02
  • D :2 February 2010
  • p :2 Feb 2010
  • P :Tuesday 2 February 2010
  • t :17:58
  • T :17:58:37 UTC
  • q :17:58:37
  • Q :17:58:37 UTC
  • f :2 February 2010 17:58
  • F :2 February 2010 17:58:37 UTC
  • g :2010-02-02 17:58
  • G :2010-02-02 17:58:37 UTC
  • i :2010-02-02
  • I :2010-02-02 17:58:37
  • M :February 02
  • m :February 02
  • R :Tue, 02 Feb 2010 17:58:37
  • r :Tue, 02 Feb 2010 17:58:37
  • s :2010-02-02T17:58:37
  • u :2010-02-02 17:58:37 UTC
  • U :Tuesday 02 February 2010 17:58:37
  • Y :2010 February
  • y :2010 February

locale: el

  • d :02/02/2010
  • D :02 Φεβρουαρίου 2010
  • p :02 Φεβ 2010
  • P :Τρίτη, 02 Φεβρουαρίου 2010
  • t :5:58 ΜΜ
  • T :5:58:37 ΜΜ UTC
  • q :5:58:37 ΜΜ
  • Q :5:58:37 ΜΜ UTC
  • f :02 Φεβρουαρίου 2010 5:58 ΜΜ
  • F :02 Φεβρουαρίου 2010 5:58:37 ΜΜ UTC
  • g :02/02/2010 5:58 ΜΜ
  • G :02/02/2010 5:58:37 ΜΜ UTC
  • i :2010-02-02
  • I :2010-02-02 17:58:37
  • M :Φεβρουαρίου 02
  • m :Φεβρουαρίου 02
  • R :Τρι, 02 Φεβ 2010 17:58:37
  • r :Τρι, 02 Φεβ 2010 17:58:37
  • s :2010-02-02T17:58:37
  • u :2010-02-02 17:58:37 UTC
  • U :Τρίτη 02 Φεβρουαρίου 2010 17:58:37
  • Y :2010 Φεβρουαρίου
  • y :2010 Φεβρουαρίου

e.g. format_date( $date, 't') ;


Custom format patterns

The previous one letter format patterns correspond to internal patterns. Instead of a single letter pattern a complete (internal) pattern compiled of the following internal tokens can be provided as input to the format_date. The supported internal tokens are:

  • Gets the year.
  • "yy" will return the last two digits of year.
  • "yyyy" will return the full integer year.

  • Gets the month.
  • "M" will return integer 1 through 12
  • "MM" will return the narrow month name, e.g. "J"
  • "MMM" will return the abrreviated month name, e.g. "Jan"
  • "MMMM" will return the month name, e.g. "January"
  • Gets the day of the week.
  • "E" will return integer 0 (for Sunday) through 6 (for Saturday).
  • "EE" will return the narrow day of the week, e.g. "M"
  • "EEE" will return the abrreviated day of the week, e.g. "Mon"
  • "EEEE" will return the day of the week, e.g. "Monday"
  • Gets the day of the month.
  • "d" for non-padding,
  • "dd" will always return 2 characters.
  • "dddd" returns "EEEE" i.e. will return the day of the week, e.g. "Monday"

  • "G" Gets the era. i.e. in gregorian, year > 0 is AD, else BC.
  • Gets the hours in 24 hour format, i.e. [0-23].
  • "H" for non-padding,
  • "HH" will always return 2 characters.

  • "a" Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.

  • Gets the hours in 12 hour format.
  • "h" for non-padding,
  • "hh" will always return 2 characters.

  • Gets the minutes.
  • "m" for non-padding,
  • "mm" will always return 2 characters.

  • Gets the seconds.
  • "s" for non-padding,
  • "ss" will always return 2 characters.

  • "z" Gets the timezone from the server machine.
  • "D" Gets the day in the year, e.g. [1-366]

  • Gets day in the month.
  • "F" for non padding
  • "FF" will always return 2 chars

  • "w" Gets the week in the year.

  • "W" Gets week in the month.

  • "K" Gets the hours in AM/PM format, e.g [1-12]

e.g. for en culture format_date( $date, 'EEE, dd MMM yyyy') Tue, 02 Feb 2010 which is not in the out the box list :)