// Get date for January 1 of the same year
// since that's where we're counting from
d1 = new Date(year,1-1,1);
// Get date for July 17
d2 = new Date(year ,mon-1,day);
// Get the difference in milliseconds
diff = d2.getTime() - d1.getTime();
// Divide by length of day (in milliseconds)
kLengthOfDay = 1000*60*60*24;
diff = diff / kLengthOfDay;
// Add 1
diff += 1;
This little script has been super helpful. I'm trying to write one that works in reverse: given the day of the year what is the date? I'm not quite getting it. Any suggestions would be appreciated. Awesome.