ahelgeson
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
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)
ASKER
This is exactly what I was looking for!
Thanks!
Thanks!
NewDate = Format$(OldDate,"MMDDYY")