Hi,
Is there any way you can add the facility to ordinalize the dates when formatting i.e. adding the nd, th, rd, and st suffixes?
Whilst this might not bother too many people, i think it would come in very handy. I'm maybe assuming there is a reason for not currently supporting it?
Cheers.
You can try using the replace filter to ordinalize like so:
{{ article.created_at | date: "%d " | replace: '1', '1st' | replace: '2', '2nd' }}
You may need to experiment here and use a mix of replace_first and replace filters to get this 100%. If you do go that route please post back with your solution for others.
Hi Jamie,
thanks for the suggestion, i think that will be a rather long winded approach to be honest. as it would obviously involve 31 replaces.
I think i'll stick with my javascript solution until a built-in formatting option is available.
Hi Rob/Jamie,
Can be done in 9 replaces as follows but it ain't pretty...
{{ article.published_at | date: '~%dth %B %Y' | replace: '~0', '' | replace: '~', '' | replace: '1th', '1st' | replace: '2th', '2nd' | replace: '3th', '3rd' | replace: '11st', '11th' | replace: '12nd', '12th' | replace: '13rd', '13th' }}
It would be a lot simpler if an ordinal existed in Liquid!
User | Count |
---|---|
22 | |
16 | |
15 | |
15 | |
14 |