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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert string to date format

Status
Not open for further replies.

joyceda59

Technical User
Apr 3, 2007
29
CA
Hi,

i created this function that takes a string parameter from a form. This string basically consists of a date in the format of mm/dd/yyyy. Now, im not too sure how to convert this string to a date so that i can compare fi the user date is greater than the current date?...here is what i did...but im sure it is wrong.

dateSelect = Date.Parse(userDate);

if(dateSelect < getDate())
{
alert("Please enter a valid date. Thank you!");
form.dateTextField.focus();
return false;
}
 
You are very close. The only thing you need to do here is parse the current date:

Code:
dateSelect = Date.parse(userDate);
[!]var now = new Date();
now = Date.parse(now);[/!]
    if(dateSelect < now)
    {
        alert("Please enter a valid date.  Thank you!");
        form.dateTextField.focus();
        return false;
    }

This will work but will not accept the current day as a valid date.



[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top