Link Search Menu Expand Document

date

The date tag outputs a string according to the given format parameter using the given date parameter. If no date provided, the current time is used.

<cms:date />
<cms:date k_page_date />
<cms:date k_page_date format='jS M, Y' />

Parameters

  • date
  • format
  • gmt
  • locale
  • charset

date

The date to be formated.
This parameter is expected to be in ‘Y-m-d H:i:s’ format (e.g. 2010-05-30 21:35:54). All date related variables set by Couch tags, e.g. k_page_date, k_page_modification_date, k_archive_date etc., are in this format.

If date is omitted, current date is taken with regard to variable ‘K_GMT_OFFSET’ from CouchCMS configuration file (config.php).

format

The date tag supports two different types of format characters - locale-aware and non locale-aware.
With locale-aware characters, you can specify that the date is to formatted according to, for example, french locale or italian locale by setting the locale parameter.
The locale-aware characters all have a % sign prefixed to them.

If parameter format is omitted the default is assumed i.e. format='F d, Y'

The locale-aware and the non locale-aware characters cannot be intermixed.

Non Locale-aware format characters


Format characterDescriptionExample returned values
Day-–-–
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase ‘L’)A full textual representation of the day of the weekSunday through Saturday
NISO 8601 numeric representation of the day of the week1 (for Monday) through 7 (for Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th. Works well with j
wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
zThe day of the year (starting from 0)0 through 365
Week-–-–
WISO-8601 week number of year, weeks starting on MondayExample: 42 (the 42nd week in the year)
Month-–-–
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
tNumber of days in the given month28 through 31
Year-–-–
LWhether it’s a leap year1 if it is a leap year, 0 otherwise.
oISO 8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.Examples: 1999 or 2003
YA full numeric representation of a year, 4 digitsExamples: 1999 or 2003
yA two digit representation of a yearExamples: 99 or 03
Time-–-–
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
BSwatch Internet time000 through 999
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds, with leading zeros00 through 59
Timezone-–-–
I (capital ‘i’)Whether or not the date is in daylight saving time1 if Daylight Saving Time, 0 otherwise.
ODifference to Greenwich time (GMT) in hoursExample: +0200
PDifference to Greenwich time (GMT) with colon between hours and minutesExample: +02:00
TTimezone abbreviation, if known; otherwise the GMT offset.Examples: EST, MDT, +05
ZTimezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.-43200 through 50400
Full Date/Time-–-–
r» RFC 2822 formatted dateExample: Thu, 21 Dec 2000 16:01:07 +0200
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 


Locale-aware format characters


Format CharacterDescriptionExample returned values
Day-–-–
%aAn abbreviated textual representation of the daySun through Sat
%AA full textual representation of the daySunday through Saturday
%dTwo-digit day of the month (with leading zeros)01 to 31
%eDay of the month, with a space preceding single digits. Not implemented as described on Windows. See below for more information.1 to 31
%jDay of the year, 3 digits with leading zeros001 to 366
%uISO-8601 numeric representation of the day of the week1 (for Monday) though 7 (for Sunday)
%wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
Week-–-–
%UWeek number of the given year, starting with the first Sunday as the first week13 (for the 13th full week of the year)
%VISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week01 through 53 (where 53 accounts for an overlapping week)
%WA numeric representation of the week of the year, starting with the first Monday as the first week46 (for the 46th week of the year beginning with a Monday)
Month-–-–
%bAbbreviated month name, based on the localeJan through Dec
%BFull month name, based on the localeJanuary through December
%hAbbreviated month name, based on the locale (an alias of %b)Jan through Dec
%mTwo digit representation of the month01 (for January) through 12 (for December)
Year-–-–
%CTwo digit representation of the century (year divided by 100, truncated to an integer)19 for the 20th Century
%gTwo digit representation of the year going by ISO-8601:1988 standards (see %V)Example: 09 for the week of January 6, 2009
%GThe full four-digit version of %gExample: 2008 for the week of January 3, 2009
%yTwo digit representation of the yearExample: 09 for 2009, 79 for 1979
%YFour digit representation for the yearExample: 2038
Time-–-–
%HTwo digit representation of the hour in 24-hour format00 through 23
%kHour in 24-hour format, with a space preceding single digits 0 through 23
%I (upper-case ‘i’)Two digit representation of the hour in 12-hour format01 through 12
%l (lower-case ‘L’)Hour in 12-hour format, with a space preceeding single digits1 through 12
%MTwo digit representation of the minute00 through 59
%pUPPER-CASE ‘AM’ or ‘PM’ based on the given timeExample: AM for 00:31, PM for 22:23
%Plower-case ‘am’ or ‘pm’ based on the given timeExample: am for 00:31, pm for 22:23
%rSame as “%I:%M:%S %p”Example: 09:34:17 PM for 21:34:17
%RSame as “%H:%M”Example: 00:35 for 12:35 AM, 16:44 for 4:44 PM
%STwo digit representation of the second00 through 59
%TSame as “%H:%M:%S”Example: 21:34:17 for 09:34:17 PM
%XPreferred time representation based on locale, without the dateExample: 03:59:16 or 15:59:16
%zEither the time zone offset from UTC or the abbreviation (depends on operating system)Example: -0500 or EST for Eastern Time
%ZThe time zone offset/abbreviation option NOT given by %z (depends on operating system)Example: -0500 or EST for Eastern Time
Time and Date Stamps-–-–
%cPreferred date and time stamp based on localExample: Tue Feb 5 00:45:10 2009 for February 4, 2009 at 12:45:10 AM
%DSame as “%m/%d/%y”Example: 02/05/09 for February 5, 2009
%FSame as “%Y-%m-%d” (commonly used in database datestamps)Example: 2009-02-05 for February 5, 2009
%sUnix Epoch Time timestampExample: 305815200 for September 10, 1979 08:40:00 AM
%xPreferred date representation based on locale, without the timeExample: 02/05/09 for February 5, 2009
Miscellaneous-–-–
%nA newline character (“\n”)-–
%tA Tab character (“\t”)-–
%%A literal percentage character (“%”)-–


gmt

By setting this parameter to ‘1’, you can get the GMT equivalent of the date provided.

locale

If you use the locale-aware format characters mentioned above, this parameter can be set to the locale desired for formatting the provided date.

<cms:date k_page_date format='%B %d, %Y' locale='french' />
<cms:date k_page_date format='%B %d, %Y' locale='italian' />
<cms:date k_page_date format='%B %d, %Y' locale='russian' charset='windows-1251'/>

This feature depends entirely on the indicated locale being available at your web server. If the locale is not available, the default 'english' locale is used.

charset

Some locales do not provide their output in UTF8 character set. This causes strange ?? characters to appear in the output.
The date tag can help converting the output to UTF8 if you can provide it with information about the charset used by the locale.

For example -

<cms:date k_page_date format='%B %d, %Y' locale='greek' charset='ISO-8859-7' />
<cms:date k_page_date format='%B %d, %Y' locale='russian' charset='ISO-8859-5' />

The following is a rough list of the charset used by different languages -

ISO

ISO-8859-1
Western Europe and Americas: Afrikaans, Basque, Catalan, Danish, Dutch, English, Faeroese, Finnish, French, Galician, German, Icelandic, Irish, Italian, Norwegian, Portuguese, Spanish and Swedish.

ISO-8859-2 - Latin 2
Latin-written Slavic and Central European languages: Czech, German, Hungarian, Polish, Romanian, Croatian, Slovak, Slovene.

ISO-8859-3 - Latin 3
Esperanto, Galician, Maltese, and Turkish.

ISO-8859-4 - Latin 4
Scandinavia/Baltic (mostly covered by 8859-1 also): Estonian, Latvian, and Lithuanian. It is an incomplete predecessor of Latin 6.

ISO-8859-5 - Cyrillic
Bulgarian, Byelorussian, Macedonian, Russian, Serbian and Ukrainian.

ISO-8859-6 - Arabic
Non-accented Arabic.

ISO-8859-7 - Modern Greek
Greek.

ISO-8859-8 - Hebrew
Non-accented Hebrew.

ISO-8859-9 - Latin 5
Same as 8859-1 except for Turkish instead of Icelandic

ISO-8859-10 - Latin 6
Latin6, for Lappish/Nordic/Eskimo languages: Adds the last Inuit (Greenlandic) and Sami (Lappish) letters that were missing in Latin 4 to cover the entire Nordic area.

Windows

Windows-1258
Vietnamese

Windows-874
Thai

Windows-1252
Latin 1 languages: Afrikaans, Basque, Catalan, Danish, Dutch, English, Faroese, Finnish, French, Galician, German, Icelandic, Indonesian, Italian, Malay, Norwegian, Portuguese, Spanish, Swahili, Swedish

Windows-1250
Central Europe languages: Albanian, Croatian, Czech, Hungarian, Polish, Romanian, Serbian (Latin), Slovak, Slovenian

Windows-1257
Baltic languages: Estonian, Latvian, Lithuanian

Windows-1251
Cyrillic languages: Azeri, Belarusian, Bulgarian, Macedonian, Kazakh, Kyrgyz, Mongolian, Russian, Serbian, Tatar, Ukrainian, Uzbek

Windows-1256
Arabic, Farsi, Urdu

Windows-1253
Greek

Windows-1255
Hebrew

Windows-1254
Turkic languages: Azeri (Latin), Turkish, Uzbek (Latin)

Examples

sample formats

A few ready-to-use format examples -

<cms:date format='Y-m-d H:i:s' />      (MySQL)
<cms:date format='D, d M Y H:i:s' />   (RSS)
<cms:date format='Y-m-d\TH:i:sP' />    (Atom)
<cms:date format='l, d-M-Y H:i:s T' /> (Cookie)
<cms:date format='l jS \of F Y h:i:s A' />
<cms:date format='F j, Y, g:i a' />
<cms:date format='m.d.y' />
<cms:date format='j/n/Y' />
<cms:date format='\i\t \i\s \t\h\e jS \d\a\y.' />
<cms:date format='D M j G:i:s T Y' />

relative dates

Dates can be set as strings, relative to current day or another date e.g.

Current -365 days: <cms:date '-365 days' />
Current +1 day: <cms:date '+1 day' />
Current +1 week: <cms:date '+1 week' />
Current +1 month: <cms:date '+1 month' />
Current +1 day 4 hours 2 seconds: <cms:date '+1 day 4 hours 2 seconds' />
First day of current week: <cms:date 'Monday this week' />
Last day of previous week: <cms:date 'Sunday last week' />
Next Thursday: <cms:date 'next Thursday' />
Last Monday: <cms:date 'last Monday' />
First day of next month: <cms:date 'first day of next month' />
First day of next month: <cms:date 'first day of next month' format='l' />
Last day of march 2009: <cms:date '2009-03 last day of this month' format='l, j/n/Y' />
Christmas Day next year: <cms:date '25 december next year' format='l, j/n/Y' />
Yesterday 14:00: <cms:date 'yesterday 14:00' format='j F, Y H:i'/>
Tomorrow: <cms:date 'tomorrow' format='Y-m-d' />
Tomorrow noon: <cms:date 'tomorrow noon' format='j F, Y H:i' />
A minute before midnight: <cms:date 'midnight -1 minute' format='H:i' />

date comparison

Compare dates with tag ‘cms:if’ & make sure the left-hand-side of the equation is a variable e.g.

<cms:set post_date="<cms:date k_page_date format='Ymd' />" />
<cms:if post_date lt "<cms:date format='Ymd' />" >
   ...
</cms:if>

usage in filters

Use variables in custom_field as well (always use double quotes " with expressions) e.g.

<cms:set curr_date="<cms:date format='Y-m-d H:i:s' />" />
<cms:pages custom_field="my_date <= <cms:show curr_date />">

Variables

This tag is self-closing and does not set any variables of its own.