Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

datetime

Summary

Formats dates/times according to settings in "datetime.ini".

Usage

{input|datetime( preset_format [, format ] )}

Parameters

NameTypeDescriptionRequired
preset_format string Preset datetime format set in "datetime.ini". Yes.
format string Custom format (when preset format is set to "custom"). No.

Returns

A string representation of the input parameter.

Description

This operator takes care of formatting dates and times according to the setting defined in "datetime.ini" (or a configuration override). In addition, the operator also allows custom formats when the "preset_format" parameter is set to "custom". A custom format must be specified using the "format" parameter. The following table reveals the different elements that can be used in a custom format.

Element

Output

Description

%a

am

Lowercase Ante meridiem and Post meridiem.

%A

AM

Uppercase Ante meridiem and Post meridiem.

%c

2004-02-12T15:19:21+00:00

ISO 8601 date

%d

08

Day of the month, 2 digits with leading zeros.

%D

Wed

A short textual representation of a day, in accordance with the "[ShortDayNames]" section of the language .INI file located in the "share/locale" directory.

%F

October

A full textual representation of a month, such as January or March.

%g

12

12-hour format of an hour without leading zeros.

%G

0

24-hour format of an hour without leading zeros.

%h

12

12-hour format of an hour with leading zeros.

%H

00

24-hour format of an hour with leading zeros.

%i

00

Minutes with leading zeros

%j

8

Day of the month without leading zeros

%l

Wednesday

A full textual representation of the day of the week.

%m

10

Numeric representation of a month, with leading zeros.

%M

Oct

A short textual representation of a month, in accordance with the "[ShortMonthNames]" section of the language .INI file located in the "share/locale" directory.

%n

10

Numeric representation of a month, without leading zeros.

%O

-0500

Difference to Greenwich time (GMT) in hours.

%r

Thu, 21 Dec 2000 16:01:07 +0200

RFC 2822 formatted date

%s

00

Seconds, with leading zeros.

%T

CDT

Timezone setting of this machine.

%U

1065589200

Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

%w

3

Numeric representation of the day of the week.

%W

41

ISO-8601 week number of year, weeks starting on Monday.

%Y

2003

A full numeric representation of a year, 4 digits.

%y

03

A two digit representation of a year.

%z

280

The day of the year.

%Z

-18000

Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.

The date used to generate the contents of this table was "12:00 AM (Midnight) CDT on October 8, 2003".

Examples

Example 1

{currentdate()|datetime( 'mydate' )}

The following output will be produced: "13:15 6 Feb 2004" (according to the configuration settings).

Example 2

{currentdate()|datetime( 'custom', '%h:%i %a %d %F %Y' )}

The following output will be produced: "01:15 pm 06 February 2004" (custom format).

Balazs Halasy (05/02/2004 10:35 am)

Geir Arne Waaler (13/10/2011 1:13 pm)

Svitlana Shatokhina, Geir Arne Waaler


Comments

  • full list of custom formats

    It seems that "custom" format strings are passed directly to php date() function. Therefore the list above is not complete, for complete list look at php documentation:
    http://php.net/date
  • /share/locale/*.ini

    Is there a way to override those /share/locale/*.ini files? There are many problems of traduction inside. For example, in french, we don't capitalize the first letter of a month nor a day (exept if it's the first word of the sentence). I don't see the interest of making a nice format that can't be used without |downcase()
    • Re: /share/locale/*.ini

      You cannot override locales, only edit existing and create new/custom ones, see
      http://ez.no/doc/ez_publish/techn..._your_site_locale#add_missing_locale
      See also http://issues.ez.no/13590

      If you find a mistake in default locale, please report to http://issues.ez.no so that it gets fixed in next releases. Thank you!
    • Re: /share/locale/*.ini

      A quick-and-dirty way :
      - modify template.ini to add PHP functions ucfirst and strtolower (add theses functions in PHPOperatorList )
      - in your template : {$node.object.published|datetime('standard')|strtolower()|ucfirst()}
      Probably not efficient and CPU consumming.
    • Re: /share/locale/*.ini

      another quick and dirty way: create a new french locale, fre-XX, and customize that one...