How to format an ordinal date pattern | Community
Skip to main content
April 19, 2021
Solved

How to format an ordinal date pattern

  • April 19, 2021
  • 1 reply
  • 1541 views

Hello,

I am trying to find a way to add formatting to a date field which will show the day as ordinal (1st, 2nd, 3rd, etc.).  I found another thread where someone asked a similar question and this was part of the response:

 

"This isn't exactly what you are after as it wont give you the ordinal (st, nd, th). If you want that you have to write you own formatting (or use one of the JavaScript date libraries, like MomentJS)"

 

Nothing else was asked about it in the thread so I don't know if the OP ever got a solution for it.  I know very little about JavaScript so would need an explanation if that is how to do it.  Any help on how to solve for this would be greatly appreciated.  Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Pulkit_Jain_

@tk0215 

You may refer to various solutions available to implement the use case with javascript.

One of the simple solutions:

 

function dateOrdinal(d) { return d+(31==d||21==d||1==d?"st":22==d||2==d?"nd":23==d||3==d?"rd":"th") };

 

 

1 reply

Pulkit_Jain_
Adobe Employee
Pulkit_Jain_Adobe EmployeeAccepted solution
Adobe Employee
May 6, 2021

@tk0215 

You may refer to various solutions available to implement the use case with javascript.

One of the simple solutions:

 

function dateOrdinal(d) { return d+(31==d||21==d||1==d?"st":22==d||2==d?"nd":23==d||3==d?"rd":"th") };