Results 1 to 3 of 3

Thread: (**resolved**)calculate days between two date given

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    asia
    Posts
    87

    Question (**resolved**)calculate days between two date given

    how should i code such code that can receive 2 date input from text box and output result (in days: date1- date2) in the 3 text box ( i'm talking about JavaScript here...)
    Last edited by ZUWARI; Nov 6th, 2002 at 12:14 AM.

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Date calculations:
    Code:
    <html>
      <body>
        <script type="text/javascript">
          var dateA = new Date();
          var dateB = new Date(2000, 0, 1, 0, 0, 0);
    
          var diff = parseInt((dateA - dateB)/86400000);
          document.writeln(diff + "<br>");
    
          document.writeln(dateA.getDate() + "-" + (dateA.getMonth() + 1) + "-" + dateA.getYear() + "<br>");
        </script>
      </body>
    </html>
    You're responsible yourself for parsing and validating the input of those textboxes. The code above shows how you can use the Date object in Javascript.
    diff will hold the difference between both dates in whole days. (The subtraction itself returns the number of milliseconds.)
    Btw new Date() will return the current date and time. When months are given numerically, keep in mind that it should be zero-based, so november will be 10, for instance.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    asia
    Posts
    87

    Lightbulb got it....

    okie, Thanks a lot riis for the code and some explanation on it.


    may the light be with u

Posting Permissions

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



Click Here to Expand Forum to Full Width