Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verify Date is Entered

Status
Not open for further replies.

Esoteric

ISP
Feb 10, 2001
93
US
How can I verify that the client has entered a valid Date?
 
Okay I figured out the IsDate command and that works good however if they enter a date like this:

13/01/01 then the SQL script just loops cause its not considered valid. Can someone please help me on this.

How can I convert that date to a format of MM/DD/YYYY?
 
This depends on where you want to validate the date. If you want to validate the date in the server side using ASP, it is much easier.

If you want to validate the date in the client side, it is much tougher and cumbersome since Javascript(which is the recommended way of writing client scripts) does not have reserved function for checking the validity of a date.

So let me know what kind of validation are you looking at.
 
Here is how I managed to get a DATE every time from the USER :0 dfrom is the input field from the user form:

if Request("dfrom") = "" then
DFROM = formatdatetime(now,2)
else
if IsDate(Request("dfrom")) then
DFROM = Request("dfrom")
DFROM = Month(DFROM) & "/" & day(DFROM) & "/" & year(DFROM)
if year(DFROM) < 1970 then
DFROM = Month(DFROM) & &quot;/&quot; & day(DFROM) & &quot;/&quot; & year(now)
end if
else
DFROM = formatdatetime(now,2)
end if
end if

First I check for any date at all if none get the current date: Secondly, I verify that it was indeed a date that was entered if not default to the current date. Thirdly, I verify that they did not enter a bogus year and for some strange reason I used 1970 as a default to compare to and this way the SQL query is ALWAYS happy with the date my LOOSERS put in, Oh, Users I mean :-()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top