Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Adding a Little Animation to Your Life
Converting a Range of URLs to Hyperlinks
Making the Formula Bar Persistent
When developing a workbook, you may have a need to place suffixes such as "st, nd, rd, or th" at the end of dates, as in "9th July." Unfortunately, there is no way to do this using the built-in date formats you can apply to individual cells. You can create custom formats for each of the four suffix types, if desired, but they would have to be applied individually based on the contents of the cell itself.
The only other option is to use some sort of conversion formula. These are easy enough to put together, but the resulting cell will not contain a true Excel date, but text. This precludes the cell contents from being used in other date-related functions. The following is an example of the type of conversion formula you can use:
=DAY(A1)&IF(OR(DAY(A1)={1,2,3,21,22,23,31}),
CHOOSE(1*RIGHT(DAY(A1),1),"st","nd ","rd "),"th")
&TEXT(A1,"mmmm, yyyy")
There are others, but they all essentially do the same thing—pull the various parts of a date apart and put them back together with the proper suffix.
If you prefer, you can also create a macro function that would return a properly formatted date, with the ordinal suffix. The following is one such macro:
Function OrdinalDate(myDate As Date)
Dim dDate As Integer
Dim dText As String
Dim mDate As Integer
Dim mmmText As String
dDate = Day(myDate)
mDate = Month(myDate)
Select Case dDate
Case 1: dText = "st"
Case 2: dText = "nd"
Case 3: dText = "rd"
Case 21: dText = "st"
Case 22: dText = "nd"
Case 23: dText = "rd"
Case 31: dText = "st"
Case Else: dText = "th"
End Select
Select Case mDate
Case 1: mmmText = " January"
Case 2: mmmText = " February"
Case 3: mmmText = " March"
Case 4: mmmText = " April"
Case 5: mmmText = " May"
Case 6: mmmText = " June"
Case 7: mmmText = " July"
Case 8: mmmText = " August"
Case 9: mmmText = " September"
Case 10: mmmText = " October"
Case 11: mmmText = " November"
Case 12: mmmText = " December"
End Select
OrdinalDate = dDate & dText & mmmText
End Function
You use the macro by simply invoking it within a cell formula. For example, if you have a date stored in cell B7, you can use the following in any other cell:
=OrdinalDate(B7)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2510) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
A Picture is Worth Thousands! Your worksheets are not limited to holding numbers and text. You can also add graphics or easily create charts based on your data. Excel Graphics and Charts, available in two versions, helps you make your graphics and charts their absolute best.