This little JavaScript will take an event or date in the future and compare it to the current date, then display how many days until that date/event occurs. Pretty neat! Lots of uses… (Marriage countdown, till school’s out countdown, etc)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ <!-- ONE STEP TO INSTALL DAYS TILL DATE: 1. Add the first code to the BODY of your HTML document --> <!-- STEP ONE: Add the first code to the BODY of your HTML document --> <body> <script LANGUAGE="JavaScript"> <!-- Original: Alan Palmer --> <!-- Web Site: http://www.users.dircon.co.uk/~apalmer --> <!--Total Java Scripts 99 - Next Step Software--> <!-- Begin var date = new Date("January 1, 2000"); var description = "the year 2000"; var now = new Date(); var diff = date.getTime() - now.getTime(); var days = Math.floor(diff / (1000 * 60 * 60 * 24)); document.write("<center><h3>") if (days > 1) { document.write(days + " days until " + description); } else if (days == 1) { document.write("Only two days until " + description); } else if (days == 0) { document.write("Tomorrow is " + description); } else { document.write("It's" + description + "!"); document.write("</h3></center>"); } // End --> </script> <!-- Script Size: 1.16 KB --> |