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 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Bahamas
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help on date comparisons

    Can someone tell me why this always produces an output
    "After today" indicating that the date is after today no matter what start date I enter (including today)

    function dated(){


    var dstart = document.forms.tstest.stdate;
    var dend = document.forms.tstest.endate;
    var dtest = document.forms.tstest.testfield;

    var startstr = dstart.value; // mm/dd/yyyy
    var endstr = dend.value;

    var xdtoday = new Date();

    var syear = parseInt(startstr.substring(6,10));
    var smonth = parseInt(startstr.substring(0,2));
    var sday = parseInt(startstr.substring(3,5));

    var eyear = parseInt(endstr.substring(6,10));
    var emonth = parseInt(endstr.substring(0,2));
    var eday = parseInt(endstr.substring(3,5));

    var xstart = new Date(syear,smonth,sday);
    var xend = new Date(eyear,emonth,eday);


    if (xdtoday > xstart )
    dtest.value = "Before today";

    if (xdtoday == xstart )
    dtest.value = "Equal today";

    if (xdtoday < xstart )
    dtest.value = "After today";

    }
    //

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    Bahamas
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    NEVER MIND!! Sorry folks

    There was a bug in the date input subroutine (forgot to subtract 1 from month)


  •  

    Posting Permissions

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