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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Date help with VBA

Status
Not open for further replies.

jpack23

Programmer
Joined
Dec 15, 2004
Messages
82
Location
US
I need to format a date so it appears as MM/DD/YYYY all the time. The problem I need to solve is getting the digits of the year into a string. During the beginning of the month the date is reading 02/1/2006 and I need it to read 02/01/2006 so I pull 2006 into the string instead of 006.

Thanks for your help
 
First I would point out the Day(), Month() and Year() functions. They would be the way I recommend doing what you want. If however you don't want to use them, then I would point out the Split() function and recommand splitting on / to get the pieces.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You could also use Right(FieldName,4) which will give you the year each time.
 
The only gotcha I would point out with using Right() is a date like 01/01/06. But if you control the data enough to be sure that won't happen then markgrizzle's solution is a good one.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Why not simply use the CDate function ?
 
got it! Thanks everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top