Jump to content

Comparing dates


SharkBait

Recommended Posts

I seem to be having troubles comparing dates in Javascript.  This is how I am doing it

 

function checkTime(id) {
var DoM = document.getElementById(id).value;
var Today = new Date();
var Minute = 60 * 1000;
var Hour = Minute * 60;
var Year = Hour * 365;
var difference;

Today =  Today.getTime();
DoM = Date.parse(DoM);
difference = Today - DoM;

if(difference > Year) {
	alert("OOW");
}
alert("Today: " + Today +"\n DoM: "+ DoM +"\n Year: "+ Year +"\n Difference: "+ difference);

}

 

the value for the id would look like "2006-04-12" and I don't think I am comparing them properly. I am trying to convert them to Unix time.. find the difference between today's date and the date entered and then see if it is greater than 1 year.

 

:)

Link to comment
https://forums.phpfreaks.com/topic/67500-comparing-dates/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.