Excel Date Question

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

NBVC

Well-known Member
Joined
Aug 31, 2005
Messages
5,828
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")
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,053
Office Version
  1. 365
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"})
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,053
Office Version
  1. 365

ADVERTISEMENT

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
 

ronaldlu

New Member
Joined
Nov 17, 2005
Messages
4
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
 

NBVC

Well-known Member
Joined
Aug 31, 2005
Messages
5,828
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")
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,990
Messages
5,834,761
Members
430,318
Latest member
ZackChua95

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
Top