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

Problems with date comparison

Status
Not open for further replies.
Sep 27, 2001
179
AU
Hi

Trying to compare a date in a text field with the current date to check for expiry. Have looked at this forum and thought I have found the answer but having issues.

Having put some alerts() in the code the form data returns in the following format: 'dd/mm/yyyy hh:mm', for testing the data in the form is 14/06/2005.

But after the Date.Parse command it returns 'Mon Feb 6 00:00:00 UTC 2006' - do I need to do something with the form data? I thought that it was already in date format.

My code is as follows:

Code:
<script language="javascript">
window.onload = function pd()
{
if (document.all._HIDDENpers_passport) {
var pd =document.all._HIDDENpers_passport.value;
}
else
{
var pd=document.all.pers_passport.value;
}
var passportdate = new Date();
var currentdate = new Date();
passportdate.setTime(Date.parse(pd));

if (passportdate < currentdate){
alert ("Passport had expired");
}
}
</script>
 
>window.onload = function pd()
Maybe you mean anonymous function here?
[tt]window.onload = function ()[/tt]

>passportdate.setTime(Date.parse(pd));
Why is there a standalone line? what does it do?

To compare Date object, you can first apply to them valueOf method and compare their results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top