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 3 of 3

Thread: Countdown

  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Australia, Melbourne
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown

    Hi, has anybody seen/got some coding that will do this:

    I have a field called Start Date. date/time only field.
    Another field called Term (mths). integer only field
    And another field called End Date. date/time only field.

    I need to determine what the End Date will be based on the Start Date and Term.

    ie:
    Start Date = 1/7/2003
    Term (mths) = 24
    End Date will be 1/7/2005

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    I have this one but you have to enter days and not months,

    Any good to you?





    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function calc_date(s) {
    days=(document.f2.daynums.value*1)//-1
    var dateArray = s.split('/');
    sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);
    if(dateArray[2].length<4){
    alert("Please Enter The Year As A Four Digit Number\n\nExample:- 2002\n\nThank You")
    return document.f2.date_to.value=""
    }
    else{
    var odate = new Date(sdate.getTime() + (days * 86400000));
    return odate.getDate() + '/' + (odate.getMonth()+1) + '/' + odate.getYear();
    }
    }
    //-->
    </SCRIPT>


    <center>
    <form name="f2">
    <P><table border=1>
    <tr><td>Start Date</td><td>Number of days</td><td>End Date</td></tr>

    <tr><td><input type="text" name="date_from" size="10" value="25/09/2002"></td><td align="center"><input type="text" name="daynums" size="4" maxlength="4" value="5"></td><td><input type="text" name="date_to" size="10"></td></tr>
    <tr><td colspan=3 align=center>
    <input type="button" value="calculate" onclick="this.form.date_to.value=calc_date(this.form.date_from.value);">
    </td></tr></table>
    </form>
    </center>


  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function getEndDate( f )
    {
        var sDate = new Date( f.elements['Start_Date'].value );
        sDate.setMonth( sDate.getMonth() + parseInt( f.elements['Term'].value, 10 ) );
        f.elements['End_Date'].value = [sDate.getMonth()+1,sDate.getDate(),sDate.getFullYear()].join("/");
    }
    Just pass a reference to the form into the function.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

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