View Full Version : Comparing 2 Dates Script

12-09-2009, 01:29 PM

I have the following script

function timeDifference(laterdate,earlierdate) {
var difference = laterdate.getTime() - earlierdate.getTime();

var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24

document.write('difference = ' + daysDifference + ' day/s ');

var laterdate = ?;
var earlierdate = ?;


and would like to insert my datein and dateout values where the ? marks are above in red.

I can call these variables into the form on the page using <%=Request("datein")%> but how do I call a variable into the script above ?


Philip M
12-09-2009, 02:41 PM
var laterdate = new Date(2009,12,3); // YYYY MM DD
var earlierdate = new Date(2009,11,28);

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

12-09-2009, 03:08 PM
Thanks I have tried that and it does work but now I need to get the date in and dateout values that are stored from the previous page.

I can write them to the screen by using <%=Request("datein")%> but I am not sure how to put this value into the function.

12-09-2009, 04:27 PM
When you use <%=Request("datein")%> to write the value from the previous page to your screen, what, exactly gets written to your page source code?

12-09-2009, 04:53 PM

The request statement writes the date from the previous page :

i.e. 12/09/2009