IsDate function is Vb.Net

P

Peter Smith

IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
What is the other way of checking the same functionality? Is there any other
know issue with the date function.
..Net 1.1 Framework.
I know alternative way of checking the same "If TypeOf MyVariable Is
DateTime Then"
Thanks,
Smith
 
A

Armin Zingler

Peter Smith said:
IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the
function? What is the other way of checking the same functionality?
Is there any other know issue with the date function.
.Net 1.1 Framework.
I know alternative way of checking the same "If TypeOf MyVariable Is
DateTime Then"


I don't see a bug. It is a valid date. It's the first of January. The year
is 2005 because it is not specified.


Armin
 
P

Peter Smith

Then what about this?
IsDate("01/2005"). This is also january first 2005?
Thanks,
Smith
 
T

Tom Shelton

IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
What is the other way of checking the same functionality? Is there any other
know issue with the date function.
.Net 1.1 Framework.
I know alternative way of checking the same "If TypeOf MyVariable Is
DateTime Then"
Thanks,
Smith

As Armin suggests, this is not a bug. Most likely, though I haven't
really bothered to check, the IsDate function most is a wrapper
for the DateTime.Parse function. And, if you read the remarks on this
function in the documentation, I would expect this behavior.

Basically, it says that the DateTime.Parse function uses the information
in the DateTimeFormatInfo for the current culture. As it parses, it
will FILL in any missing values (month, day, year) with the
values from the current date... Meaning that, the DateTime.Parse will
turn your string:

"01/01" into a date of "01/01/05". And that, is a valid date.
 
T

Tom Shelton

Then what about this?
IsDate("01/2005"). This is also january first 2005?
Thanks,
Smith

See my previous post... Esentially, DateTime.Parse will interpret that
as January 20, 2005 (basically, adding todays day in). Again, it will
return a valid date, so the IsDate Function will return true.
 
T

Tom Shelton

IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
What is the other way of checking the same functionality? Is there any other
know issue with the date function.
.Net 1.1 Framework.
I know alternative way of checking the same "If TypeOf MyVariable Is
DateTime Then"
Thanks,
Smith

One more note... If this is a problem for you - you could always write a
replacement using DateTime.ParseExact. ParseExact will only return a
date if the date is in the specified format. So, in psuedo code it
would look something like:

public function myIsDate (date as string) as boolean
try
datetime.parseexact (....)
return true
catch
return false
end try
end fuction
 
A

Armin Zingler

Peter Smith said:
Then what about this?
IsDate("01/2005"). This is also january first 2005?

Yes:
Msgbox CDate("01/2005")

Tom's reply answers why.

If you don't like the flexibilty of the function - you are not the only
one - you can write one on your own (or find one for free).


Armin
 

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

Top