Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting DateAdd output 1

Status
Not open for further replies.

GettinBi

Technical User
May 1, 2008
18
0
0
CA
I'm trying to put a date 7 days from today into a Word document. So far I've found the easiest way is through a macro using the dateadd function, but I can only get it formatted in the System's Short Date format, which is currently set to yyyy-mmm-dd, so I get 2008-Jun-26 when I'd like June 26, 2008.
The article I pulled this from showed the formula as
***
Sub PrevMonth()
Dim mBefore As Date
mBefore = Format(DateAdd("m", -1, Date), "mmmm d, YYYY")
Selection.InsertBefore mBefore
End Sub
***
but the date doesn't format as expected. Is there a way to tell vb to use the long date, like with the vblongdate statement?

Thanks,

 
Code:
Sub PrevMonth()
   Dim mBefore As [red]String[/red]
   mBefore = Format(DateAdd("m", -1, Date), "mmmm d, YYYY")
   Selection.InsertBefore mBefore
End Sub

You are carefully formatting it and then converting it back to a date which is then converted using your system locale settings.
 
Thanks! That's exactly what I was missing.

Problem solved.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top