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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question number of days between 2 dates

    I have a form where people can request a project from me. On the form are two fields, due date and request date. I ask for 10 business days to turn any project around. I'd like to be able to...

    1. first calculate the number of BUSINESS (monday - Friday) days there are between the due date and request date.

    2. If that number is below 10, prompt a message basically saying that I may not be able to get their project done.

    3. Ask them to confirm their order even with this warning message.

    4. If they say Yes to the confirmation, then the form continues on. If they say No, then the form submission stops and I do not receive the submission.


    Any ideas on how I can do this? If you could provide the calculation code, I'd appreciate it!

    thanks

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First, go here, a good Date object reference
    http://www.w3schools.com/js/js_datetime.asp

    Now, here's the process I'd take

    1) read input fields and create date objects from their values
    2) Verify validity of dates
    3) Loop, incrementing the older date by one day each iteration
    3a) If day is a weekday, add to a counter
    3b) Exit loop when older date is eqal to new date
    4) return result

    I'll let you have a stab at it first.
    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”

  • #3
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Beetle, I'll see if I can do it based on what you said. if not, I'll be back!!

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts


    <HTML>
    <HEAD>
    <TITLE>Document Title</TITLE>
    </HEAD>
    <BODY>

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function calc_date2() {
    from=document.f3.date_from.value
    to=document.f3.date_to.value

    var fromArray = from.split('/');
    fromdate = new Date( fromArray[2], fromArray[1]-1, fromArray[0]);

    var toArray = to.split('/');
    todate = new Date( toArray[2], toArray[1]-1, toArray[0]);

    document.f3.daynums.value=(todate-fromdate)/86400000

    }
    //-->
    </SCRIPT>
    <P>Calculate the days from start date to end date.
    <center>
    <form name="f3">
    <P><table border=1>
    <tr><td>Start Date</td><td>End Date</td><td>Number of days</td></tr>
    <tr><td><input type="text" name="date_from" size="10" value="25/09/2002"></td>
    <td><input type="text" name="date_to" size="10" value="26/09/2002"></td>
    <td align="center"><input type="text" name="daynums" size="4" maxlength="4" value=""></td></tr>
    <tr><td colspan=3 align=center>
    <input type="button" value="calculate" onclick="calc_date2()">
    </td></tr></table>
    </form>
    </center>
    </BODY>
    </HTML>











  •  

    Posting Permissions

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