delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

with a continual count up.  The date and time can be fixed in the code:
May 16th, 2009 2:22:00am
Can anyone point me in the right direction?  Does what I'm saying even make sense?


I'm looking for some code that will display how old someone is.  I tried searching but am having a hard time figuring out what to search for.  The closest I could find was this:
http://www.rcs.k12.va.us/csjh/agecounter.htm
but I want something that shows
years, months, weeks, days, hours, minutes, seconds
with a continual count up.  The date and time can be fixed in the code:
May 16th, 2009 2:22:00am
Can anyone point me in the right direction?  Does what I'm saying even make sense?

TOP

LOL!  Sarcasm noted but as I stated I haven't found one that gives years, months, weeks, days, hours, minutes and seconds.  The ones that you have in your search criteria only gives me days hours and minutes.  Please look at the link that I posted and thanks in advance for your help.

TOP

Why don't you just take that code and add the months and seconds? It's simple arithmetic...

TOP

Ok I decided to do it for you since I was bored. I don't even know if this is right, so if some JS guru like Winters could validate this for me.. (I know I should declare variables with var, this is just the base layout of the example, I edited this slightly to show how easy it is)
Code:
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <script type="text/javascript">
  5. <!-- hide this script tag's contents from old browsers
  6. function lifetimer(){
  7.         today = new Date()
  8.         BirthDay = new Date(document.live.age.value)
  9.         timeold = (today.getTime() - BirthDay.getTime());
  10.         sectimeold = timeold / 1000;
  11.         secondsold = Math.floor(sectimeold);
  12.         msPerDay = 24 * 60 * 60 * 1000 ;
  13.         msPerMonth = 24 * 60 * 60 * 1000 * 30 ;
  14.         timeold = (today.getTime() - BirthDay.getTime());
  15.         e_monthsold = timeold / msPerMonth;
  16.         monthsold = Math.floor(e_monthsold);
  17.         e_daysold = timeold / msPerDay;
  18.         daysold = Math.floor(e_daysold);
  19.         e_hrsold = (e_daysold - daysold)*24;
  20.         hrsold = Math.floor(e_hrsold);
  21.         minsold = Math.floor((e_hrsold - hrsold)*60);
  22.         secsold = Math.floor((e_hrsold - hrsold)*360);
  23.         document.live.time0.value = monthsold
  24.         document.live.time1.value = daysold
  25.         document.live.time2.value = hrsold
  26.         document.live.time3.value = minsold
  27.         document.live.time4.value = secsold
  28.         window.status = "Well at the moment you are " + secondsold + "............ seconds old.";
  29.         timerID = setTimeout("lifetimer()",1000)
  30. }
  31. // -- done hiding from old browsers -->
  32. </script>
  33. </head>
  34. <body>
  35. <FORM name="live">
  36. Please enter your age::<INPUT TYPE="text" NAME="age" VALUE="" SIZE=20>
  37. Example: (november 1,1966) <BR><BR><BR>
  38. <INPUT TYPE="button" NAME="start" VALUE="Start Timer" ONCLICK="lifetimer(this.form)">
  39. <INPUT TYPE="reset" NAME="resetb" VALUE="Reset Age">
  40. <BR><BR>
  41. <TABLE border=0>
  42. <TR><TD>You are months  old:</TD>
  43. <TD>
  44. <input type="text" name="time0" value="" size=8>
  45. </TD>
  46. </TR>
  47. <TR><TD>You are days old:</TD>
  48. <TD>
  49. <INPUT TYPE="text" NAME="time1" VALUE="" size=8>
  50. </TD>
  51. </TR>
  52. <TR><TD>Plus hours old:</TD>
  53. <TD>
  54. <INPUT TYPE="text" NAME="time2" VALUE="" size=8>
  55. </TD>
  56. </TR>
  57. <TR><TD>Plus minutes old:</TD>
  58. <TD><INPUT TYPE="text" NAME="time3" VALUE="" size=8></TD>
  59. </TR>
  60. <TR><TD>Plus seconds old:</TD>
  61. <TD><INPUT TYPE="text" NAME="time4" VALUE="" size=8></TD>
  62. </TR>
  63. </TABLE>
  64. </FORM>
  65. </body>
  66. </html>
Copy Code

TOP

abstract:

with a continual count up.  The date and time can be fixed in the code:
May 16th, 2009 2:22:00am
Can anyone point me in the right direction?  Does what I'm saying even make sense?


Cool, thanks for the help.  Several questions:
How do I just put the date in the code itself instead of in the text box?
How do I add years?
How do I have it continually counting the seconds?
How do I make the days and months all fold into each other?  I'm looking for so many years and the remaining time divided into months, then the remaning time divided into days, etc...  In other words there should never be more than 12 months and there should never be more than 31 days and no more than 60 seconds, etc...

TOP

By "in" the code, I assume you mean write to the document? Find an element ID and then populate it with the variable.
Add years, again, by using basic arithmetic. Keep following the same principle
Continually adding, sounds like a clock sort of function. Google it, I am not proficient enough to recommend you some code.
Don't know, but guessing it is also some more basic arithmetic like if(numberOfMonths > 12){year++;numberOfMonths=0;}
yet again, don't take my response to heart, I don't pretend to know what I'm talking about.



with a continual count up.  The date and time can be fixed in the code:
May 16th, 2009 2:22:00am
Can anyone point me in the right direction?  Does what I'm saying even make sense?

TOP

Back Forum