Westside2004
asked on
Dates and Military time validation needed
Hi,
I have two fields with dates and times in the format:
03/20/2006 16:07 (military times)
I need to ensure the following
That field 1 cannot be more than one day earlier than field 2.
How can I do this using JavaScript?
Thx
-ws
I have two fields with dates and times in the format:
03/20/2006 16:07 (military times)
I need to ensure the following
That field 1 cannot be more than one day earlier than field 2.
How can I do this using JavaScript?
Thx
-ws
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think this would be simpler:
var d1= //field1
var d2= //field2
var temp = new Date(d1);
temp.setDate(d1.getDate()+ 1);
if(temp>d2) return false;
var d1= //field1
var d2= //field2
var temp = new Date(d1);
temp.setDate(d1.getDate()+
if(temp>d2) return false;
Yes it would - if you made a date of d2 too.
More way to skin a cat:
aDay = 86400000;
function isMoreThanADay(strDate1,st rDate2) {
var d1 = new Date(strDate1).getTime();
var d2 = new Date(strDate2).getTime();
return (d2-d1)>aDay
}
function validate(theForm) {
if (isMoreThanADay(theForm.da te1.value, theForm.da te2.value) ) {
.
.
More way to skin a cat:
aDay = 86400000;
function isMoreThanADay(strDate1,st
var d1 = new Date(strDate1).getTime();
var d2 = new Date(strDate2).getTime();
return (d2-d1)>aDay
}
function validate(theForm) {
if (isMoreThanADay(theForm.da
.
.
function showDateDiff(elem1, elem2)
{
var d1 = new Date(Date.parse(document.g
var d2 = new Date(Date.parse(document.g
var diff = (d1-d2)/86400000;
if (Math.abs(diff) > 1) alert("true");
}