Displaying the creation date of an article in Cotonti: all methods in Examples
A complete list of modifications to the PAGE_CREATED tag in Cotonti: direct output, format change, timestamp, conditional output, and global configuration via $Ldt.
Outputting the Article Creation Date (PAGE_CREATED) in Cotonti: All Methods with Examples
This article covers all the main ways to output the article creation date in Cotonti templates. The examples use the creation date: August 16, 2026, 14:31:30 (Unix timestamp 1755345090). An empty date is stored as 0 and when formatted gives 01.01.1970 00:00 — therefore, always use PAGE_CREATED_STAMP to check if a date exists.
1. Direct Output of the Ready Date
The tag PAGE_CREATED is already formatted by the function cot_date('datetime_medium', ...).
Syntax:
{PAGE_CREATED}
Result for a visitor:
16.08.2026 14:31
If the date is empty (0):
01.01.1970 00:00
2. Output of the Raw Timestamp
The tag PAGE_CREATED_STAMP contains the original numeric value (Unix timestamp). It is used for checks and further processing.
Syntax:
{PAGE_CREATED_STAMP}
Result:
1755345090
3. Using cot_date() with Predefined $Ldt Formats
The cot_date() function accepts a key from the $Ldt array, providing localized output.
Any format supported by the PHP date() function can be used.
5. Converting Timestamp to MySQL Date (cot_stamp2date)
The function returns only the date in YYYY-MM-DD format (without time).
Syntax:
{PAGE_CREATED_STAMP|cot_stamp2date($this)}
Result:
2026-08-16
6. Conditional Output Only for Non‑Empty Dates
Since a zero timestamp (0) when formatted gives “01.01.1970”, use PAGE_CREATED_STAMP for checking.
6.1. With the ready value PAGE_CREATED
Syntax:
<!-- IF {PAGE_CREATED_STAMP} -->
<span>Creation date: {PAGE_CREATED}</span>
<!-- ENDIF -->
Result when date is not empty:
Creation date: 16.08.2026 14:31
Result when date is empty: (nothing is displayed)
6.2. With a custom format
Syntax:
<!-- IF {PAGE_CREATED_STAMP} -->
{PAGE_CREATED_STAMP|cot_date('date_full', $this)}
<!-- ENDIF -->
Result when date is not empty:
16.08.2026
7. Legacy Tags (if legacyMode is enabled)
If legacyMode is enabled in the Cotonti settings, the following tags are additionally available:
PAGE_DATE — analogue of PAGE_CREATED
PAGE_DATE_STAMP — analogue of PAGE_CREATED_STAMP
Usage example:
{PAGE_DATE_STAMP|cot_date('d.m.Y', $this)}
Result:
16.08.2026
8. Global Format Change via $Ldt
By default, PAGE_CREATED is built using $Ldt['datetime_medium']. To change the format for all pages at once, override this key in your theme's or plugin's language file.
Example (theme.en.lang.php):
$Ldt['datetime_medium'] = 'Y-m-d H:i';
After that, the direct output {PAGE_CREATED} will yield:
2026-08-16 14:31
9. Relative Time (optional)
To display “X ago”, the cot_build_timegap() function is used, but calling it in a template with two arguments is difficult. Usually this is done in a PHP plugin: