...

View Full Version : Check if Dates are Same



Kylena
10-15-2003, 07:53 AM
I've the following code to check if both dates are the same, if so, the user has to change. But it's not doing what I like to.


var f = document.forms[0];

if (f.ApptDate.value = f.DateCreated.value) {
alert("Appointment Date cannot be today!")
f.ApptDate.value = "";

return false
}

Upon running the code, ApptDate has the same value as DateCreated.

DateCreated is Today's date. I want ApptDate to be later than DateCreated, thus the validation will check if the date is the same as today.

lavalamp
10-15-2003, 11:17 AM
This line is wrong:

if (f.ApptDate.value = f.DateCreated.value) {

it should be:

if (f.ApptDate.value == f.DateCreated.value) {

nolachrymose
10-15-2003, 12:58 PM
You could convert them to date objects, and check:


if(ApptDate.getTime() >= DateCreated.getTime())

Hope that helps!

Happy coding! :)

Kylena
10-16-2003, 04:44 AM
Thank you both! :thumbsup:

lavalamp
10-16-2003, 06:06 PM
Happy to help. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum