View Full Version : Load a .js file depending on Day of the Year

06-18-2004, 06:24 AM
I am fairly new to JavaScript, but have been able to figure a lot out, but what I have been trying to do for three weeks is this: on my website: www.southportvfd.com, I have a counter that counts up from the date the Fire Department was establish October 2, 1895. The months, days, hours, minutes, and seconds are fine, but the YEAR field also comes from the time of the local user. So since we were established on Oct 2, 1895, we have not been around for 109 years until Oct 2, 2004 . . . but since it has been 109 years since Jan 1 1895, the counter says 109 years. My solution is that I made 2 files: myclock.js (which counts from 1895), and myclock_.js (which counts from 1894)

I AM LOOKING FOR: a JavaScript that will load "/js/myclock.js" if the current date is Oct 2 through Dec 31, and load "/js/myclock_.js" if the current date is Jan 1 through Oct 1.



06-18-2004, 02:41 PM
var script = document.createElement("script")

//determine js file
var today = new Date();
var mm = today.getMonth(); //this starts at 0
var jsFile = (mm<9 || (mm==9 && today.getDate()==1)) ? "/js/myclock_.js" : "/js/myclock.js"

script.setAttribute("src", jsFile);

Willy Duitt
06-18-2004, 02:42 PM
Obviously, the script is not acurately calculating the years/monthes/days. And since that script is over bloated at 10086 characters and 749 lines. I would suggest finding another script. You may find one here by searching the forums.

06-18-2004, 06:48 PM
Thank you very much glenngv, I really appreciate you taking the time to help me out.

Willy Duitt:
It was pretty difficult to find a script that counted up from a specific date down to the second, and used custom images to do it. If you have a better script to use, I am open to change, but as long as what I'm using now works, I'm going to stick with it.