Snippet returns the date in a specified format. It can also:
- Return the current date;
- Return document pubdate by default, or createon if pubdate is empty;
- Display month as a string (like
January
,February
,March
, etc); - Return short formated date (like
Today
,Yesterday
,Day before yesterday
).
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.48
- Snippet name:
ddGetDate
. - Description:
<b>2.2</b> Snippet returns the date in a specified format.
. - Category:
Core
. - Parse DocBlock:
no
. - Snippet code (php): Insert content of the
ddGetDate_snippet.php
file from the archive.
- Create a new folder
assets/snippets/ddGetDate/
. - Extract the archive to the folder (except
ddGetDate_snippet.php
).
-
date
- Desctription: Date.
- Valid values:
integer
string
'now'
— current date
- Default value: Pubdate or createdon (if pubdate is empty).
-
format
- Desctription: Date format to display.
- Valid values:
string
- Default value:
'd.m.y'
-
monthToStr
- Desctription: Display month as string. If it's true month in
format
must be specified as'month'
. - Valid values:
0
1
- Default value:
0
- Desctription: Display month as string. If it's true month in
-
shortFormat
- Desctription: Display shorted fromated date. If it's true date in
shortFormat
must be specified as'short'
. - Valid values:
string
- Default value: —
- Desctription: Display shorted fromated date. If it's true date in
-
lang
- Desctription: Month names language.
- Valid values:
'ru'
'en'
- Default value:
'ru'
[[ddGetDate?
&date=`now`
&format=`Y`
]]
Returns:
2021
[[ddGetDate]]
Returns:
27.03.21
[[ddGetDate?
&date=`[*tvDate*]`
&format=`d month Y`
&monthToStr=`1`
&lang=`en`
]]
Returns:
27 March 2021
[[ddGetDate?
&shortFormat=`short, G:i`
]]
Returns:
Yesterday, 9:48.
\DDTools\Snippet::runSnippet([
'name' => 'ddGetDate',
'params' => [
'date' => 'now',
'format' => 'd.m.Y'
]
]);