A
Armin Zingler
romy said:What's the easiest way to verify the user had entered a valid date ?
Call Date.Parse in a Try/Catch block. If there's no excecption the date was
valid.
Armin
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
romy said:What's the easiest way to verify the user had entered a valid date ?
romy said:What's the easiest way to verify the user had entered a valid date ?
romy said:What's the easiest way to verify the user had entered a valid date ?
This is what internally iw done in IsDateCall Date.Parse in a Try/Catch block. If there's no excecption the date
was valid.

Jason Pettys said:I'm not sure whether IsDate uses Exceptions as the primary
mechanism. Does anyone know for sure whether IsDate uses an
exception for invalid dates (1) always, (2) sometimes, or (3) never?
If I found out that it did I wouldn't use it; here's an msdn blog
that talks about it, the best quote being, "...pretend that the
throw statement makes the computer beep 3 times, and sleep for 2
seconds. If you still want to throw under those circumstances, go
for it."
http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx
The feedback from Jeremy Wilson on this next page seems to indicate
that IsDate does not (or at least doesn't use it alone):
http://blogs.crsw.com/mark/archive/2005/04/06/829.aspx
If I found out that IsDate DID rely primarily on an exception for
invalid values I would use something similar to that referenced in
this next article, the idea being to catch most invalid dates
without throwing an exception:
http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci960388_tax293037,00.html
Cor Ligthert said:Armin,
This is what internally iw done in IsDate
(You can check it by setting the stop on all throwed events in the
debugger)
![]()
(sometimes we forget the simple thingsJason Pettys said:I'm not sure whether IsDate uses Exceptions as the primary mechanism. Does
anyone know for sure whether IsDate uses an exception for invalid dates
(1) always, (2) sometimes, or (3) never?
Exactly. I am as well active in the dotNet general newsgroup. You understandOk ok, I've read it now.(sometimes we forget the simple things
(searched for TryParse first)) But, what do C# people do? That's probably
why I didn't think of IsDate. Furthermore, *if* you use IsDate you should
also use CDate instead of Date.Parse.

System.ParseI see three ways to convert:

Cor Ligthert said:"Armin Zingler">
?
System.Convert (ToDateTime)
CDate
Cor Ligthert said:Armin
Exactly. I am as well active in the dotNet general newsgroup. You
understand the discussions that has been?

One of few VisualBasic methods beside this that I like very much is
the CDate (because it converts as well very easy Database Items. The
docs from MSD say that this conversion methods are much improved
comparissing with VB6 and that there is not any reason not to use
them. In contrary it is advised.
By the way, there is somebody in this newsgroup active who does not
agree this with me.
![]()

As a string input is usually taken from
the user - you know, the slowest part of the chain - there is absolutely no
need to optimize this process.
Jason Pettys said:Extracted from full quote below:
If you had a high-traffic ASP.NET site with a lot user-entered date
validation required, is there still "absolutely no need to optimize
this process"?
Armin said:If you have one user sitting in front, is there any reason to forbid
Try/Catch?
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.