Date of Birth Counter Using Javascript

Submitted by: 
Language: 
Visitors have accessed this post 2014 times.

In this chapter, You will learn to make a Date of birth counter into days, hours and time. Just follow the tutorial below and download the source code.

DIRECTIONS

Creating our HTML code

  1. <FORM name="live">
  2.  
  3. <BR><BR><BR>
  4.  
  5.  
  6. <TABLE border=1>
  7. <tr>
  8. <td><INPUT TYPE="button" NAME="start" VALUE="Start" ONCLICK="lifetimer(this.form)"></td>
  9. <td><INPUT TYPE="reset" NAME="resetb" VALUE="Reset Age"></td>
  10. </tr>
  11. <tr>
  12. <td>Date of birth:</td>
  13. <td><INPUT TYPE="text" NAME="age" VALUE="" SIZE=20 placeholder="January 10, 1994"> </td>
  14. </tr>
  15. <TR><TD>You are days old:</TD>
  16.  
  17. <TD>
  18.  
  19. <INPUT TYPE="text" NAME="time1" VALUE="" size=8>
  20.  
  21. </TD>
  22.  
  23. </TR>
  24.  
  25. <TR><TD>Plus hours old:</TD>
  26.  
  27. <TD>
  28.  
  29. <INPUT TYPE="text" NAME="time2" VALUE="" size=8>
  30.  
  31. </TD>
  32.  
  33. </TR>
  34.  
  35. <TR><TD>Plus minutes old:</TD>
  36.  
  37. <TD><INPUT TYPE="text" NAME="time3" VALUE="" size=8></TD>
  38.  
  39. </TR>
  40. </FORM>

Creating our javascript code

  1. <SCRIPT LANGUAGE="JAVASCRIPT">
  2. <!-- hide this script tag's contents from old browsers
  3. function lifetimer(){
  4.  
  5. today = new Date()
  6.  
  7. BirthDay = new Date(document.live.age.value)
  8.  
  9. timeold = (today.getTime() - BirthDay.getTime());
  10.  
  11. sectimeold = timeold / 1000;
  12.  
  13. secondsold = Math.floor(sectimeold);
  14.  
  15. msPerDay = 24 * 60 * 60 * 1000 ;
  16.  
  17. timeold = (today.getTime() - BirthDay.getTime());
  18.  
  19. e_daysold = timeold / msPerDay;
  20.  
  21. daysold = Math.floor(e_daysold);
  22.  
  23. e_hrsold = (e_daysold - daysold)*24;
  24.  
  25. hrsold = Math.floor(e_hrsold);
  26.  
  27. minsold = Math.floor((e_hrsold - hrsold)*60);
  28.  
  29. document.live.time1.value = daysold
  30.  
  31. document.live.time2.value = hrsold
  32.  
  33. document.live.time3.value = minsold
  34.  
  35. window.status = "Well at the moment you are " + secondsold + "............ seconds old.";
  36.  
  37. timerID = setTimeout("lifetimer()",1000)
  38.  
  39. }
  40. // -- done hiding from old browsers -->
  41.  
  42. </script>

You have now created a date counter that counts days, hours and minutes between the date today and the date you entered. For more suggestions and questions feel free to comment below or email me at [email protected]


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.