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 to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel-like date calculations

    I have created a very easy spreadsheet which enables the user to calculate the day on which the medication supply runs out.

    The sheet considers
    • number of tablets available
    • number of tablets to take per day (1 or 2)
    • start date


    By dividing the number of tablets by the number of days, the function will provide the total number of days which the medication will cover. By using MIN it will round the number to the next lower integer. At the end it substract the output by one (due to the fact that the first tablet is already taken on the start date).

    Now I would like to make this available on a website as a calculator. It should be something like a form where only the yellow fields can be edited. Does anyone have an idea which tools I could use for this? Ideally, it should be possible to embed this in an wordpress page.

    Many thanks in advance.

    Cheers,

    Philipp

    (you can see the spreadsheet in the attachment)
    Attached Thumbnails Attached Thumbnails Excel-like date calculations-spreadsheet.png  

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    621
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Maybe this will help:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
      <head>
    
        <title>Medicine Supply</title>
    
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="Content-Language" content="en-US" />
        <meta name="Author" content="James Alarie - jalarie@umich.edu" />
        <meta name="description" content="Calculate the day on which the medication supply runs out." />
        <meta name="keywords" content="calculate,day,medication,supply" />
        
        <script type="text/javascript">
          /*<![CDATA[*/
    
      function ComputeIt() {
        f1=document.forms[0];                           // abbreviation
        
        I_StartDate       =f1.F_StartDate.value;
        I_AvailableTablets=f1.F_AvailableTablets.value;
        I_NumberPerDayI   =f1.F_NumberPerDay.selectedIndex;
        I_NumberPerDay    =f1.F_NumberPerDay.options[I_NumberPerDayI].value;
        
        S_StartDate=new Date(I_StartDate)*1;            // milliseconds since 1970-01-01
        S_StartDate=S_StartDate/(24*60*60*1000);        // ...days as a decimal
        S_StartDate=Math.floor(S_StartDate);            // ...days integer
        S_Days=Math.floor(I_AvailableTablets/I_NumberPerDay);
        S_OutOfSupplyAfter=S_StartDate*1+S_Days*1-1;
        
        S_Date=new Date((S_OutOfSupplyAfter*1+1)*24*60*60*1000);
        S_Year =S_Date.getFullYear();
        S_Month=S_Date.getMonth()*1+1;                  // month as 1-12
        S_Date =S_Date.getDate();
        
        O_Date=S_Year+'-'+S_Month+'-'+S_Date;
        f1.F_OutOfSupplyAfter.value=O_Date;
        
        return true;
      } // ComputeIt
    
          /*]]>*/
        </script>
    
      </head>
    
      <body class="body1">
       <div id="body">
    <!-- Page Header -->
        <div id="header">
          <h1>Medicine Supply</h1>
          <hr />
        </div>
    
    <!-- Content -->
        <div id="content">
          <br />
          <noscript>
            <p class="notice">
              You must have scripting enabled to make full use of this page.
            </p>
          </noscript>
          
          <div class="center">
            <form method="post" action="javascript:void(0);">
             <div class="form">
              <table border="1" cellspacing="2" cellpadding="2"
                  summary="This table is used for layout purposes only.">
                <caption class="caption2"><b>Medication Supply</b></caption>
                <tbody>
                  <tr>
                    <td>
                      <label for="F_StartDate">Start Date</label>
                    </td>
                    <td>
                      <input type="text" size="20" value="?" name="F_StartDate" id="F_StartDate" alt="First date" onfocus="this.select();" />
                    </td>
                    <td>
                      as YYYY-MM-DD
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label for="F_AvailableTablets">Available Tablets</label>
                    </td>
                    <td>
                      <input type="text" size="20" value="?" name="F_AvailableTablets" id="F_AvailableTablets" alt="Number of Available Tablets" onfocus="this.select();" />
                    </td>
                    <td>
                      Enter the number of tablets that you have
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label for="F_NumberPerDay">Number per Day</label>
                    </td>
                    <td>
                      <select name="F_NumberPerDay" id="F_NumberPerDay">
                        <option>1</option>
                        <option>2</option>
                      </select>
                    </td>
                    <td>
                      How many do you take each day?
                    </td>
                  </tr>
                  <tr>
                    <td colspan="3">
                      <input type="button" value="Compute" onclick="ComputeIt();" />&nbsp; 
                      <input type="reset" value="Reset" title="Reset" />&nbsp; 
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label for="F_OutOfSupplyAfter">Out of Supply After</label>
                    </td>
                    <td>
                      <input type="text" size="20" value="?" name="F_OutOfSupplyAfter" id="F_OutOfSupplyAfter" alt="Take the last Tablet on this Date" onfocus="this.select();" />
                    </td>
                    <td>
                      result:&nbsp; take the last tablet on this date
                    </td>
                  </tr>
                </tbody>
              </table>
             </div><!-- form -->
            </form>
            
          </div><!-- center -->
      
        </div>
      
    <!-- Page Footer -->
        <div id="footer">
          <br clear="all" /><hr />
          Written on December 23, 2012, by:&nbsp;
          <a href="mailto:jalarie@umich.edu">James Alarie</a>.
        </div>
    
       </div>
      </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
    •