Who Does She Think She Is?

Blog Post

Javascript Birthday Counter

Posted by Joni in General

I found a great little snippet of Javascript code that counts down to your birthday. Customize the look of the “button” to coordinate with your blog template.

Place this anywhere on your page (usually a sidebar):

<SCRIPT language=javascript type=text/javascript>
now = new Date
thisYr = now.getYear()
if (thisYr < 1900) { thisYr = thisYr + 1900 } nextYr = thisYr + 1 birthday = new Date(thisYr,7,13) if (birthday .getTime() > now.getTime()) { birthday.setYear(nextYr) } function dayToDays(inTime) { return (Math.floor(inTime.getTime() / (1000 * 60 * 60 * 24))) } function daysTill(inDate) { return dayToDays(inDate) - dayToDays(now) } </SCRIPT> <div align="center" style="text-transform: uppercase; margin: 3px; padding: 2px; border: 3px dotted #CCCCCC; font-size: 12px; font-weight: 400; background: #FFFFFF; color: #E60000;"><SCRIPT language=javascript type=text/javascript> document.write("<b>" + daysTill(birthday) + "</b> days until my birthday<br />"); </SCRIPT></div> <br>

To personalize it, on this line:

birthday = new Date(thisYr,7,13)

change 7 to your birthmonth; change 13 to your birthday. Also you may change any of the style attributes as indicated. Have fun!

Leave a Comment

Your email address will never be published or shared and required fields are marked with an asterisk (*).

Scroll Up