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

How to format an ordinal date pattern

Avatar

Avatar
Boost 1
Level 1
TK0215
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
TK0215
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
TK0215
Level 1

19-04-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 25
Employee
PulkitJain
Employee

Likes

69 likes

Total Posts

70 posts

Correct Reply

33 solutions
Top badges earned
Affirm 25
Boost 50
Give Back 10
Establish
Boost 25
View profile

Avatar
Affirm 25
Employee
PulkitJain
Employee

Likes

69 likes

Total Posts

70 posts

Correct Reply

33 solutions
Top badges earned
Affirm 25
Boost 50
Give Back 10
Establish
Boost 25
View profile
PulkitJain
Employee

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

 

 

Answers (0)