Skip to the content
Documentation

datetime

No ratings yet

Summary

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

Usage

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

Parameters

Name Type Description Required
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).

Contributors

Comments (5 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. full list of custom formats

    zurgutt ·

    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

  2. /share/locale/*.ini

    Adrien ·

    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()

    1. Re: /share/locale/*.ini

      Jérôme ·

      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.

    2. Re: /share/locale/*.ini

      Gaetano ·

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

Comments

Add a comment

Comments are read by a moderator before they appear.