Age counter.
I just wrote up a simple age counter you can put on your blog. Simply copy and paste this code in the <head> of your html doc:
<!-- Age counter --> <script type ="text/javascript">
function agecount(dob){ //present date. var today = new Date(); var cday = today.getDate(); var cmonth = today.getMonth(); var cyear = today.getFullYear(); //dob date. var birth = new Date(dob); var bday = birth.getDate(); var bmonth = birth.getMonth(); var byear = birth.getFullYear(); //calculate. var age = cyear - byear -1; //if not birthday yet. if( bmonth < cmonth ) { age++;} // If it's past birth month. if( bmonth == cmonth && bday < cday) { age++; } // If it's past birth day. if(bmonth == cmonth && bday == cday)//its your birthday.) { age++; document.write("It's my birthday! "); } document.write(age +" yrs"); } </script>
Then paste this in the html doc wherever you want the result to show up simply type: [if you paste it in the description it will NOT display properly on mobile apps atm].
<script>agecount("mm/dd/yyyy")</script> (with your date of birth in the format above eg "02/01/2014" is February 1st 2014. You need the double quotation marks).
Then it's done! it will automatically display your age. On your birthday is outputs "It's my birthday!" in front of your new age. Have a try :D










