dcsimg
How can I validate a input date is 30 days older than today?
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jack_zhang
Posted On:   Monday, December 3, 2001 09:16 AM

for example: an input is 10/20/2001 and today is 12/03/2001. I need got an error message window that says your input is 30 days older than today. This is emergency, please answer as soon as possible. Thanks.

Re: How can I validate a input date is 30 days older than today?

Posted By:   jack_zhang  
Posted On:   Thursday, December 6, 2001 10:18 AM

I figure out myself how it should be. The key is that we have to convert input date format MM/DD/YYYY to standard date format so that we can compare them. However, thanks very much for all the answers.


function DateDiffFromToday(tempdate)
{
var today=new Date();
var todaytime=today.getTime();
var index=tempdate.value.indexOf("/");
var monthstr=tempdate.value.substr(0,index);
var tempstring=tempdate.value.substr(index+1,tempdate.value.length);
index=tempstring.indexOf("/");
var daystr=tempstring.substr(0,index);
var yearstr=tempstring.substr(index+1,tempdate.value.length);
var month = monthstr-0;
var day = daystr-0;
var year = yearstr-0;
var temp=new Date(year,month-1,day);
var temptime=temp.getTime();
var difftime=todaytime-temptime;
var diffindays= Math.floor(difftime / (1000 * 60 * 60 * 24));
if(diffindays>=30){
alert("The date is 30 days old than today");
}
}

Re: How can I validate a input date is 30 days older than today?

Posted By:   Firat_Tiryaki  
Posted On:   Thursday, December 6, 2001 01:15 AM

You can simply substract the dates as below


day1 = new Date("December 5, 2002 00:00:00");

day2 = new Date("December 10, 2002 00:00:00");

alert((day2-day1)/86400000);


The result is given in miliseconds, when you divide the result by 86400000, the result is a day-count result.

Re: How can I validate a input date is 30 days older than today?

Posted By:   Nitesh_Naveen  
Posted On:   Wednesday, December 5, 2001 12:15 PM

Try this one out...

function compareDate(inputDate) {
var currDate = new Date();
var inDate = new Date(inputDate);
dateDiff = (currDate.getYear()-inDate.getYear())*12*30+(currDate.getMonth()-inDate.getMonth())*30+currDate.getDate()-inDate.getDate();
if(dateDiff>30)
alert("your input is 30 days older than today");
}

Re: How can I validate a input date is 30 days older than today?

Posted By:   Sujatha_Gopal  
Posted On:   Tuesday, December 4, 2001 12:44 AM

Try this Link :


http://html_help4u.tripod.com/datediff.html
About | Sitemap | Contact