Light-weight, fast, simple and powerful!
Translations of this page?:

display the date of the page

To display the date of the page use this code:

<?php echo $this->date(); ?>

If you want to change the format of the date, you can pass it as the first parameter of the method like this:

<?php echo $this->date('%A, %e %B %Y'); ?>

The default date returned is the page’s creation date. If you want to display the last updated time of this page do it like this:

<?php echo $this->date('%a, %e %b %Y', 'updated'); ?>

Other values that can be used instead of updated are:

  • created — (default) which returns the date the page was initially stored in the database, no matter what “Status” it had; and
  • published — which returns the date the page was first saved with the “Status” set to “Published”

For more information about the date format, check this site:

On Windows, and rarely in other settings, the use of %e may prevent any date appearing! In this case, use %d in its place. (See PHP Bugs for more information.) A work-around is given below.

How to translate every date in your layout

Set the locale to your language using the setlocale PHP function. Put this string at the top of your layout:

<?php setlocale(LC_ALL, 'fr_CA.utf8'); ?>

The example is for Canadian French. Other language and variant codes can be found in the ICU Locale Explorer. For more information about the function consult the PHP manual.

Note: for different languages in the admin/backend, use Administration > Settings for default. Languages can also be set for each user in the Users > [Username] settings.

Work-around for the %e problem

In the note above, users were warned that in Windows and some other environments, use of the %e parameter (day-of-the-month number with no leading zeros) can break the output. The solution is to use the reliable %d parameter instead, which gives day numbers less than 10 with a leading 0.

If it is important to have the date in the form “6 August 2009” rather than “06 August 2009”, you can use this work-around:

<?php echo $this->date('%#d %b %Y'); ?>

If that code does not produce the desired result, this more verbose method should work:

<?php $day = ltrim($this->date('%d'), '0'); echo $this->date("$day %b %Y"); ?>

Both versions remove the leading zero, where present.

howto/display_the_date_of_the_page.txt · Last modified: 2012-02-08 10:30 by David
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 / design by yello studio / Wolf CMS Inside