IsDate resolve as True when should be False

G

Guest

I need to store the date as a string of 8 numbers but still test if I have a
valid date. I tested by formatting my string as a date (mm/dd/yyyy) and then
applied IsDate function. However, if I invalidate the "date" by removing a
character from the year, IsDate still resolves as TRUE. So, I tried the
following test and still couldn't make my test work. I don't know what I am
doing wrong. Can anyone help?

My test code:

Dim strDate As String
strDate = "01/01/200" 'I removed a digit from the year to invalidate the
date.
MsgBox strDate & " is " & IsDate(strDate)

Message says: 01/01/200 is True
Shouldn't it say False?
 
A

Allen Browne

January 1 in the year 200 is a valid date.

If you want to specify a date range (e.g. between 1900 and 2200) you could
use this kind of thing, with error handling to trap things that really are
not dates (such as 13/13/2000):

iYear = Year(CDate("01/01/200"))
If iYear < 1900 Or iYear > 2000 Then
 
G

Guest

I see that I can't use IsDate with a date stored as a string (mmddyyyy) even
if I format it to look like a date prior to testing (mm/dd/yyyy). I can only
use IsDate with an actual date variable. I'll use your method instead to test
for valid ranges. I thought it might have been a defect in Access because
IsDate("13/01/2000") did resolve as False, although my example of
IsDate("01/01/200") did not.

Thanks again for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

#Name? 1
Back up using compression software 10
IsDate() Function 2
Stumped By Dates 4
make exported excel field uppercase 2
Filter on date problem 8
Filter a Report with Several Criteria 2
Date Format dd/MM/yyyy 5

Top