Textpattern has localized strings for almost everything, but dates are under servers responsibility. This is reasonable, since dates are more than just months/days names, but can be a problem if some locales are not installed on the server. For example, even if I switch Textpattern current language to Russian, <txp:posted />
will output 26 March 2013, 21:21, since ru_RU
locale is not available on our server.
This is where etc_date
intervenes. It allows you to define your own date strings to display dates in the language of your choice. Moreover, you can use custom calendars, to transform 1799-11-09 into 18 Brumaire An VIII (though currently only Gregorian, Hijri and Jalali calendars are available).
Even if you do not need to localize dates, etc_date
can come handy, since it understands expressions like today, next Friday, etc.
Enough words, place to the action.
<txp:etc_date />
outputs 29 September 2024, 02:52, the current server date.<txp:etc_date date="next Friday" />
outputs 4 October 2024, 00:00.<txp:etc_date date="posted" />
outputs 26 March 2013, 21:21, this article’s publish date.<txp:etc_date date="posted" lang="fr_FR" />
outputs 26 March 2013, 21:21, sincefr_FR
locale is available on this site.<txp:etc_date date="posted" lang="ru_RU" format="%A %d %B %Y" />
outputs Вторник 26 марта 2013. This time,ru_RU
is unavailable, but month and weekday names are defined in plugin preferences.<txp:etc_date calendar="hijri" lang="ar_AR" format="%d %B %Y" />
outputs 25 Rabiulawal 1446.<txp:etc_date calendar="jalali" lang="fa_IR" format="%d %B %Y" />
outputs 1403 ژوئیه 8.
Date ranges
<txp:etc_date date="sunday..sunday +6 days" wraptag="blockquote" break=", ">
<txp:etc_date timestamp='<txp:etc_timestamp />' format="%A" /> -
<txp:etc_date timestamp='<txp:etc_timestamp />' format="%A" lang="ru_RU" />
</txp:etc_date>
Sunday - Воскресенье , Monday - Понедельник , Tuesday - Вторник , Wednesday - Среда , Thursday - Четверг , Friday - Пятница , Saturday - Суббота
Dates comparison:
<txp:etc_if_date value="12-24..12-31" format="%m-%d">
Merry Christmas and Happy New Year!
<txp:else />
Yet <txp:etc_date_diff from="now" to="December 25" format="%a" /> days until Christmas...
</txp:etc_if_date>
Yet 86 days until Christmas...
<txp:etc_if_date date="expires" compare="now..+3 days" format="%s">
This article expires in less than three days!
</txp:etc_if_date>
According to <txp:etc_date_diff from="posted" to="now" format="%a days and %h hours" />
, this very article is published 4204 days and 4 hours ago.
Localized date strings
Localized date strings are not supplied with the plugin, but here are some links kindly posted by our users:
File(s)
- File: etc_date.txt [25.59 kB] (1300 downloads, ~10 per month)