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!

Simple date comparison 1

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Joined
Nov 21, 2003
Messages
4,773
Location
US
I evidently have users that don't know what year they live in. This is made obvious by the fact that they keep putting future dates in a report they're required to fill out.

Anyway... I have a masked-input date field, and I need a simple javascript validation to pop an alert if they put in a future date.

Something like:
Code:
var today = New Date();
var strDate = New Date(document.form.thedate.value);

if(strDate > today){
   alert("Time travel hasn't been invented yet!  That date is in the future!);
   return false;
}

.... so, why is this kicking my butt today? :-(


Just my 2¢

"What the captain doesn't realize is that we've secretly exchanged his dilithium crystals for new Folger's Crystals." -- My Sister
--Greg
 
I would check the dates using the .getTime() function, assuming the dates in the report are done to the nearest day, then the following should work

Code:
var today = New Date();
var strDate = New Date(document.form.thedate.value);

if(strDate.getTime() > tomorrow.getTime()){
   alert("Time travel hasn't been invented yet!  That date is in the future!);
   return false;
}
 
my bad on the if statement, should be today.getTime() not tomorrow.getTime()
 
<LOL>

That's just what I needed... except that New can't be capitalized.... I looked at that code for 15 mins, going "WHY ISN'T IT WORKING!!!" <LOL>



Just my 2¢

"What the captain doesn't realize is that we've secretly exchanged his dilithium crystals for new Folger's Crystals." -- My Sister
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top