Excel Date Question

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this.

It should account for any day and put the appropriate ending.

Change all occurrences of A1 to match your date cell.


=IF(AND(RIGHT(DAY(A1),2)<>"11",RIGHT(DAY(A1),1)<>"0"),DAY(A1)&CHOOSE(RIGHT(DAY(A1),1),"st","nd","rd","th","th","th","th","th","th"),DAY(A1)&"th")
 
Upvote 0
Another possibility:

=DAY(A1)&LOOKUP(DAY(A1),{1,"st";2,"nd";3,"rd";4,"th";21,"st";22,"nd";23,"rd";24,"th";31,"st"})
 
Upvote 0
NBVC said:
=IF(AND(RIGHT(DAY(A1),2)<>"11",RIGHT(DAY(A1),1)<>"0"),DAY(A1)&CHOOSE(RIGHT(DAY(A1),1),"st","nd","rd","th","th","th","th","th","th"),DAY(A1)&"th")

NBVC: This gives 12nd and 13rd
 
Upvote 0
Thanks, I ended up writing a function

Function GetDayFormat(x)


Select Case CStr(Day(x))
Case "1": g = "1st"
Case "2": g = "2nd"
Case "3": g = "3rd"
Case "21": g = "21st"
Case "22": g = "22nd"
Case "23": g = "23rd"
Case "31": g = "31st"
Case Else: g = Day(x) & "th"

End Select
GetDayFormat = g

End Function
 
Upvote 0
Oaktree said:
NBVC said:
=IF(AND(RIGHT(DAY(A1),2)<>"11",RIGHT(DAY(A1),1)<>"0"),DAY(A1)&CHOOSE(RIGHT(DAY(A1),1),"st","nd","rd","th","th","th","th","th","th"),DAY(A1)&"th")

NBVC: This gives 12nd and 13rd

Thanks Oaktree. I remembered to take into account the 11th but not the 12th and 13th.

This fixes that
Code:
=IF(AND(RIGHT(DAY(A1),2)<>"11",RIGHT(DAY(A1),2)<>"12",RIGHT(DAY(A1),2)<>"13",RIGHT(DAY(A1),1)<>"0"),DAY(A1)&CHOOSE(RIGHT(DAY(A1),1),"st","nd","rd","th","th","th","th","th","th"),DAY(A1)&"th")
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top