Customising date format as 31st December 2015 (st / th / nd / rd) | Community
Skip to main content

Customising date format as 31st December 2015 (st / th / nd / rd)

  • November 4, 2015
  • 2 replies
  • 0 views

We needed a specific way to display the task due date in a macro:

{ticket.due_date_with_timestamp}

We noticed that with the above it would insert the date like so:

2015-12-31T12:00:00Z

However we wanted to display it like this:

31st December 2015

There was no instructions on how to format it where it would apply the appropriate end of the day "th" "st" "nd" "rd". 

To achieve this you will need to simply copy and paste the following in your macro:

{% assign d = ticket.due_date_with_timestamp | date: "%-d" %} {% case d %}{% when "1" or "21" or "31" %}{{ d }}st{% when "2" or "22" %}{{ d }}nd{% when "3" or "23" %}{{ d }}rd{% else %}{{ d }}th{% endcase %} {{ticket.due_date_with_timestamp | date: "%B"}} {{ticket.due_date_with_timestamp | date: "%Y"}}

 

I hope this helps somebody as it did for us! 

 

All the best,

Ben

ParcelBroker.co.uk

This topic has been closed for replies.

2 replies

  • November 4, 2015

Nice one!


Jennifer16
  • November 10, 2015

Thanks for sharing this!