Click to See Complete Forum and Search --> : Date Comparison


w33man
02-21-2003, 03:54 AM
if (isFieldEmpty(document.forms[0].StartDate,"You must enter an Event Start Date!","text")) return false;
s =Date.parse (document.forms[0].StartDate.value);

if (isFieldEmpty(document.forms[0].ExpiryDate,"You must enter an Event Expiry Date!","text")) return false;
x = Date.parse(document.forms[0].ExpiryDate.value) ;

function Xpire()
{
alert ("Error !!! Expiry Date cannot come before start date!","text");
document.forms[0].ExpiryDate.value = ("")
}
ydate = ((s) - (x));
if (ydate <"0")
{
Xpire();
if (isFieldEmpty(document.forms[0].ExpiryDate,"You must enter an Event Expiry Date!","text")) return false;
}
else
alert ("Finished");
document.forms[0].Submitted.value = ("Yes");
document.forms[0].submit();

When comparing the dates the parse uses the day value first therefore e.g. 28 feb is regarded as being after the 27 mar

skriptor
02-21-2003, 04:50 AM
Hi,
I think your program works ok:

s =Date.parse ("28 feb 2003");
alert( s );
x = Date.parse("27 mar 2003") ;
alert( x );
alert((s - x));
ydate = ((s) - (x));
if (ydate <0)
{
alert("s < x");
}else {
alert ("Finished");
}
}

=> Result is 's<x' and this is allright.

w33man
02-21-2003, 04:58 AM
Hi skriptor

The problem lies in the way that the date.parse works with
document.forms[0].???.value

when I view the date it give me e.g.
28/02/2000 = 1112480000
27/03/2002 = 1012580002

the problem lies in the first part of the object i.e. 111 is greater than 101

skriptor
02-21-2003, 07:41 AM
Hi,
parse can't work with your input. It use IETF-format "Mon, 25 Dec 1995 13:30.00 GMT+0430". So you can 't use parse.method.
Good luck, skriptor.

khalidali63
02-21-2003, 07:56 AM
See if this is what you had in your mind.

http://68.145.35.86/skills/javascripts/DateRangeSelector.html

cheers

Khalid

w33man
02-21-2003, 08:19 AM
thanx khalid

The script I'm using creates a calendar picker, I think this is creating my problem the option would be to use the list box picker you provided to evaluate and then calculate

khalidali63
02-21-2003, 08:41 AM
I think I did not understand your last post.
The above script shows you how to get difference between 2 dates...and thats what you wnated to find out ..right?

:-)

Khalid

w33man
02-21-2003, 09:49 AM
nearly right

The date picker is of the calendar type (see attatchment)

and parseing the date gives the wrong infomation for calculation

ie 21 03 2004 = parse no (1125 0200 0000)
21 02 2004 = 1125 6156 0000
21 02 2003 = 1094 0796 0000
21 03 2003 = 1094 1660 0000

w33man
02-21-2003, 09:50 AM
so sorry forgot to attach

khalidali63
02-21-2003, 09:54 AM
still no attachment...lol.
attach the full code if its possible.

Khalid

w33man
02-21-2003, 09:55 AM
had to convert to a jpg sorry bout that

khalidali63
02-21-2003, 09:58 AM
better put all files in a zip file and attach that..

w33man
02-21-2003, 10:02 AM
Too many charercters in the source so i attatched it

khalidali63
02-21-2003, 10:22 AM
There is no html portion with it.

w33man
02-21-2003, 10:23 AM
there in lies another problem Khalid this particular program is written in Domino Designer (Lotus Notes)

khalidali63
02-21-2003, 12:07 PM
Ok I have doen some changes to the script, and added a function that will compare the dates.

check out the file.

Save it as an html file and run it.

Cheers

Khalid

w33man
02-22-2003, 05:27 AM
Cheers Khalid some nice scripting do you mind if I myabe change some functionality to accomodate the user

again many thanx

khalidali63
02-22-2003, 05:55 AM
No problems....

glad to be of any help..

Cheers

Khalid