ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing Date Formats in VBA (https://www.excelbanter.com/excel-programming/374291-changing-date-formats-vba.html)

PhilM

Changing Date Formats in VBA
 
Hi

I have a date format of dd/mm/yyyy in a string (ie 02/10/2006) for
filename purposes to save my file I need this to format as "2nd October
2006" how can I do this?


Bob Phillips

Changing Date Formats in VBA
 
Use this function

Function OrdinalDate(inDate As Date)
Dim tmp
If Day(inDate) = 11 Or Day(inDate) = 12 Or Day(inDate) = 13 Then
tmp = "th"
ElseIf Right(Day(inDate), 1) < 4 Then
Select Case Right(Day(inDate), 1)
Case 1: tmp = "st"
Case 2: tmp = "nd"
Case 3: tmp = "rd"
End Select
Else
tmp = "th"
End If
OrdinalDate = Day(inDate) & tmp & Format(inDate, " mmmm yyyy")
End Function

like so

ActiveWorkbook.SaveAs Filename:= OrdinaDate(Date)

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"PhilM" wrote in message
ps.com...
Hi

I have a date format of dd/mm/yyyy in a string (ie 02/10/2006) for
filename purposes to save my file I need this to format as "2nd October
2006" how can I do this?





All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com