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.
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 "invalid format"
You could do the same check with the day and the year.
eg if val(mid(inputdate,4,2)) <> day(inputdate) then
msgbox "invalid format"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.