MODX is written in PHP, and as such relies on the core PHP date functions, such as strftime. The discussion here can be quite complex because the strftime and strtotime functions deploy similar arguments, but they are not identical.
The discussion here pertains primarily to the following content areas:
createdon
— creation date;deletedon
— deletion date;editedon
— last edit date;publishedon
— date the resource was published;pub_date
— date the resource should appear in the publication;unpub_date
— unpublish date.
Unix timestamps and formatted dates
Depending on the source and method of obtaining the value, you may get either a Unix timestamps or a formatted date. Unix timestamps are recognized as a large integer (representing the number of seconds since January 1, 1970).
In MODX date
output modifier, which is used to format dates using the PHP strftime()
function, expects a unix timestamp. To convert a formatted date to a unix timestamp, you will use the strtotime
output modifier.
So if a value of, say, [[*madeon]]
returns a formatted date, you need to first convert it to a unix timestamp using [[*madeon:strtotime]]
before you can format it with date
, but if the value immediately returns a unix timestamp, you can skip this.
General Examples
It’s impossible to list every possible example, but here are some common ways to format dates using MODX output filters.
Example output | Filter parameters |
---|---|
Thu Apr 14, 2011 | [[*createdon:strtotime:date=`%a %b %d, %Y`]] |
18 April 2011 | [[*createdon:strtotime:date=`%d %B %Y`]] |
Monday, April 18, 2011 | [[*createdon:strtotime:date=`%A, %B %d, %Y`]] |
2011-04-18 | [[*createdon:strtotime:date=`%Y-%m-%d`]] |
Depends on configuration | [[*createdon:strtotime:date=`[[++manager_date_format]]`]] |
All parameters
The date output modifier internally implements the PHP strftime function, so all strftime documentation applies to the date output modifier as well.
To change the language used by the date
output modifier (e.g. for day and month names), configure the locale
in the system settings in MODX accordingly.
Code | Display | Example |
---|---|---|
%a | Short name of the day of the week | Sun |
%A | Full name of the day of the week | Sunday |
%b | Short name of the month | Jan |
%B | Full name month | January |
%c | Local date and time | Wed Jan 7 00:22:10 2010 |
%C | Century (year divided by 100, range from 00 to 99) | 20 |
%d | Day of the month (01 to 31) | 03 |
%D | Same as %m/%d/%y | 04/29/10 |
%e | Day of month (1-31) | 3 |
%H | Hour (24-hour clock) | 00-23 |
%I | Hour (12-hour clock) | 01-12 |
%l (lowercase L) | Hour in 12-hour clock with a space preceding one digit | 1-12 |
%j | Day of the year | 001 to 366 |
%m | Month | 01 to 12 |
%M | Minute | 00 to 59 |
%n | Newline | \n |
%P | before or after noon | am |
%p | Before or after noonня | AM |
%r | Same as %I:%M:%S %p | 08:23:11 PM |
%R | Same as %H:%M | 23:11 |
%S | Second | 00 to 59 |
%t | Symbol tabs | \t |
%T | Same as %H:%M:%S | 26:12:27 |
%u | Day of the week (Monday=1) | 01 to 07 |
%w | Day of the week (Sunday=0) | 00 to 06 |
%x | Only date | 01/25/09 |
%X | Time only | 02:58:12 |
%y | Two-digit year | 09 |
%Y | Four-digit year | 2025 |
%Z or %z | Time zone offset or name | -005 or EST |
%% | Literal % | % |
Server Compatibility Note
Not all servers support all formatting options, in particular on Windows “%e” is not supported, and “%z” and “%Z” return the time zone name instead of the offset. On Mac, %P
is not supported.