Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Check if Dates are Same

    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.

    Code:
    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.

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This line is wrong:

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

    it should be:

    if (f.ApptDate.value == f.DateCreated.value) {
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could convert them to date objects, and check:

    Code:
    if(ApptDate.getTime() >= DateCreated.getTime())
    Hope that helps!

    Happy coding!

  • #4
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you both!

  • #5
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Happy to help.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •