Trying to format date with ordinal suffix

It does not seem possible to have a date such as dec 19th, 1st 22nd etc with strftime.
[[+publishedon:date=%b %jS, %Y]]
https://doc.bccnsoft.com/docs/php-docs-7-en/function.strftime.html

That indeed does not appear to be supported by strftime() which is locale-aware but does not offer ordinals. To use the ordinal suffix you can use date() with the S character.

I don’t think that’s available out of the box as an output filter so you’d need a custom snippet combining strftime() (for localised days and such) and date() for the ordinal suffix.

Thanks for reponding, sounds a better idea than
Bob ray which had syntax errors and tried the updated solution, does not instil confidence!
https://forums.modx.com/thread/13979/changing-format-of-publishedon-date?page=2

Based on Mark’s suggestion, this should work. Unlike my post from 9 years ago, I tested this one (though not with it as a placeholder tag). :wink:

[[*publishedon:dateWithOrdinals]]
<php?
/* dateWithOrdinals snippet */
$date = strtotime($input);
return date("jS M Y", $date );

Is there a good reason why ordinal suffixes are not available in strftime?

I don’t really know, but it’s possible that they wanted to keep the weight down. Adding that capability for multiple languages would have made it a pretty hefty function.

A better question might be why the MODX date: output modifier calls strftime() rather than date(). :wink:

You are right, date() can only handle month day names in english.
https://stackoverflow.com/questions/5941121/php-strftime-date-or-datetime-which-is-better

Tried php function in placeholder.
Gives base date 1st jan 1970!
It does give me the suffix though.

You might try calling the placeholder uncached.

[[!+publishedon ...]]

Just tried that flushing permissions, clearing cache in browser and logging out.
Then closing browser.
Will give up for now and try later.
Thanks very much for taking the time to respond.

Is the placeholder inside another tag or in a Tpl chunk for a snippet tag that’s nested inside something else?

It is a tpl chunk of pdoResaurses wrapped in a span.

I just tested it in a tpl chunk with getResources and it worked for me. I called getResources uncached, and the placeholder cached:

    [[!getResources ...]]]
    [[+publishedon:dateWithOrdinals]]
<php?
/* dateWithOrdinals snippet */
$date = strtotime($input);
return date("jS M Y", $date );

Are you sure all the resources are published and have a publishedon date set?

Seems to be working with getResources and not pdoResources?

FWIW, I tested it with pdoResources and it worked for me.

<span class="date"><svg class="icon icon-calendar"><use xlink:href="#icon-calendar"></use></svg> Posted on [[+publishedon:date:dateWithOrdinals]]</span>

This works in both snippet calls!
Just added date.
pdoResources with &tpl returns this for publishedon.
[publishedon] => 1591181945
I do not know why it is working for you?
I am running xampp on manjaro linux.

That should be

[[+publishedon:dateWithOrdinals]]

[[+publishedon:dateWithOrdinals]] does not work with both, but [[+publishedon:date:dateWithOrdinals]] does.

Hmm … what do you see with just this, a timestamp, or a human-readable date?

[[+publishedon]]

[publishedon] => 1591181945