PDA

View Full Version : Comparing Times



Bobafart
Mar 8th, 2007, 04:32 PM
I am trying to compare two times - 20 minutes apart - the current time and a time that I get from a database using an xmlhttprequest.



function compareDates(){
var currentDate = new Date();
var XMLDate = XXX; -- what format should the XML date be outputted as from the server (I am using PHP)?
var dateDifference = currentDate - XMLDate;
if (dateDifference > 20){
alert("the unit is built");
} else{

alert(dateDifference + "minutes left");

}

}

shyam
Mar 8th, 2007, 05:14 PM
Thu Mar 08 2007 18:12:13 GMT+0100 is the accepted format

but there's a simpler date constructor like this

new Date(2006, 1, 23, 6, 30, 30)
which is what u should be aiming at...

tonyp12
Mar 8th, 2007, 05:45 PM
Use milliseconds

if ( (currentDate.getTime() - Date.parse(xmldate) ) < 1200000 )


http://www.w3schools.com/jsref/jsref_obj_date.asp