Link to home
Start Free TrialLog in
Avatar of ahelgeson
ahelgesonFlag for United States of America

asked on

Breaking down a date

I have a program that asks a user for a date.  I take the input and make sure it's valid and then I convert it using CDate into the MM/DD/YYYY format.

However, the system I am writing this program for requires the date to be in the MMDDYY format.  How can I cut out the proper fields from the MM/DD/YYYY to get it into the MMDDYY format?
ASKER CERTIFIED SOLUTION
Avatar of ripnasty
ripnasty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use the Format$ function:

NewDate = Format$(OldDate,"MMDDYY")
First, I'd recommend using a date-picker function so that you don't have to validate the date (since it can be in many different formats.)

Once you have a date in date format (CDate will do that), you can use Month(TheDate), Day(TheDate), Year(TheDate), then tack these pieces together.

Alternately, you can convert the date to a string, then extract the pieces:

left$(MyDate,2) & mid$(MyDate, 4,2) & right$(MyDate,2)
Avatar of ahelgeson

ASKER

This is exactly what I was looking for!

Thanks!