View Full Version : Check if Dates are Same

10-15-2003, 08: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.

10-15-2003, 12:17 PM
This line is wrong:

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

it should be:

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

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

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

Hope that helps!

Happy coding! :)

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

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