Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to format an ordinal date pattern

TK0215
Level 1
Level 1

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

1 Accepted Solution
PulkitJain
Correct answer by
Employee
Employee

@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")
};

 

 

View solution in original post

1 Reply
PulkitJain
Correct answer by
Employee
Employee

@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")
};

 

 

View solution in original post