Excel Date Question

Some videos you may like

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
7,988
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
7,988

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")
 

Watch MrExcel Video

Forum statistics

Threads
1,118,055
Messages
5,569,941
Members
412,299
Latest member
agentless
Top