Checking Military Dates
Hi Otto,
B2 doesn't work but B3 does.
Sub CheckDate()
b1 = "20030231"
b2 = DateSerial(Left(b1, 4), Mid(b1, 5, 2), Right(b1, 2))
b3 = Mid(b1, 5, 2) & "/" & Right(b1, 2) & "/" & Left(b1, 4) 'mm/dd/yyyy
Debug.Print b1, b2, b3, IsDate(b3)
End Sub
--
John
johnf202 at hotmail dot com
"Otto Moehrbach" wrote in message
...
Excel 2002, Win XP
I'm working with the new military 8 digit date system.
For instance 20030704 is 4 July 2003.
I need to check if the user entry is a valid date. I'm using:
DateFrom8 = DateSerial(Left(j, 4), Mid(j, 5, 2), Right(j, 2)) to convert
the
8 digits into the intended date. The conversion works fine.
The problem is when I try to check if the user entered the 8 digits
correctly. IOW, 13 months is bad, 32 days is bad. But the above
DateSerial
function will simply take the 13 months as being one month more than the
date if 12 were entered. The same with too many days. No matter what the
numbers entered, DateSerial will produce a valid date. Using
IsDate(DateSerial(...........) will always produce a True.
My question: Is there a function other than DateSerial that I can use
with IsDate to show False if the user enters too many months or days? Or
is
there another way to check the validity of the date?
Obviously I can check Mid(j, 5, 2) and see if it's 12. The problem
is
more with the days.
Thanks for your help. Otto
|