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

Date Validation

Status
Not open for further replies.

hollaback

Technical User
Joined
Apr 8, 2003
Messages
6
Location
US
I'm using VB with an Excel Spreadsheet/Macro. One of my inputboxes has the user input the date in the format mm/dd/yy. How do I validate that the user inputed the date in the correct format.

Thanks

Paul
 
Hi

I don't think you should be so strict on the format in which the date is captured. After all, a date is a date. You can format the date any way you like with the 'format' command. eg format(inputdate,"mm/dd/yyyy"). If you want to validate that it is a valid date then use the 'isdate' command.
If you really want to validate the format then you could use the commands 'Day','Month' and 'Year' eg.

if month(inputdate) <> val(left(inputdate,2)) then
msgbox &quot;invalid format&quot;

You could do the same check with the day and the year.
eg if val(mid(inputdate,4,2)) <> day(inputdate) then
msgbox &quot;invalid format&quot;

Enjoy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top