Close Date Expand Location Next Open/Close Previous 0.5 of 5 stars 1 of 5 stars 1.5 of 5 stars 2 of 5 stars 2.5 of 5 stars 3 of 5 stars 3.5 of 5 stars 4 of 5 stars 4.5 of 5 stars 5 of 5 stars Repeat Slide Current slide

AP style month abbreviations with strftime in Liquid

AP style is particular about how dates are formatted in various circumstances. strftime uses %b for month abbreviations, but its format (the first three letters of the month: Jan, Feb, etc) differs from AP style’s preferred abbreviations for some months. This Liquid snippet converts strftime’s month abbreviations to AP style:

{{ object | date: '%b. %e, %Y' | replace: 'Mar.', 'March' | replace: 'Apr.', 'April' | replace: 'May.', 'May' | replace: 'Jun.', 'June' | replace: 'Jul.', 'July' | replace: 'Sep.', 'Sept.' }}

For example, this Liquid code…

{% assign today = '2020-09-15' %}
<p class="current-date">{{ today | date: '%b. %e, %Y' | replace: 'Mar.', 'March' | replace: 'Apr.', 'April' | replace: 'May.', 'May' | replace: 'Jun.', 'June' | replace: 'Jul.', 'July' | replace: 'Sep.', 'Sept.' }}</p>

…will generate this HTML:

<p class="current-date">Sept. 15, 2020</p>