PC Review


Reply
Thread Tools Rate Thread

Changing Date Formats in VBA

 
 
PhilM
Guest
Posts: n/a
 
      4th Oct 2006
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 With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      4th Oct 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing date formats Susan Microsoft Excel Misc 1 23rd Jul 2009 02:23 AM
changing date formats Bernie R. Microsoft Excel Worksheet Functions 5 13th Feb 2008 01:25 AM
changing date formats Heine Microsoft Excel Worksheet Functions 4 3rd May 2007 03:54 PM
changing date formats chris.howes Microsoft Excel Misc 2 1st Feb 2004 12:31 PM
Changing date formats paul Microsoft Excel Worksheet Functions 1 18th Sep 2003 11:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:23 PM.