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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.