Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing date formats Susan Excel Discussion (Misc queries) 1 July 23rd 09 02:23 AM
changing date formats Heine Excel Worksheet Functions 4 May 3rd 07 03:54 PM
Changing date formats? lakegoddess Excel Discussion (Misc queries) 5 January 6th 06 05:26 PM
Changing Imported Date Formats Craig Lloyd Excel Worksheet Functions 5 December 20th 05 02:30 PM
Changing Imported Date Formats Craig Lloyd Excel Worksheet Functions 0 December 20th 05 12:51 PM


All times are GMT +1. The time now is 06:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"