Having pieced this together from other Internet examples, I thought I'd share a rendition of getting dates for a particular period such as "the next five days".
Cheers, Todd
<SCRIPT LANGUAGE="JavaScript1.2"> <!-- gets first day of period --> var today = new Date(); var targetDay = new Date(today.getTime() + 0 * 24 * 60 * 60 * 1000); var targetDayNum = today.valueOf() + 1000 * 60 * 60 * 24 * 0; var d2 = (new Date(targetDayNum)); var dayNum = d2.getDay(); var dayName = ["Sun.","Mon.","Tues.","Wed.","Thurs.","Fri.","Sat."][dayNum]; var monthNum = d2.getMonth(); var monthName = ["Jan.","Feb.","March","April","May","June","July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."][monthNum]; var beginDay = dayName + ", " + monthName + " " + d2.getDate(); <!-- --> <!-- gets last day of period --> <!-- --> var today = new Date(); var targetDay = new Date(today.getTime() + 6 * 24 * 60 * 60 * 1000); var targetDayNum = today.valueOf() + 1000 * 60 * 60 * 24 * 6; var d2 = (new Date(targetDayNum)); var dayNum = d2.getDay(); var dayName = ["Sun.","Mon.","Tues.","Wed.","Thurs.","Fri.","Sat."][dayNum]; var monthNum = d2.getMonth(); var monthName = ["Jan.","Feb.","March","April","May","June","July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."][monthNum]; var endDay = dayName + ", " + monthName + " " + d2.getDate(); document.write(beginDay + " - " + endDay); </SCRIPT> <!-- notes: * To identify the begin and end period dates you only need to change the number of days in the targetDay and targetDayNum contructors. In this case "0" (today) and "6" (six days from today) were used. * Add: ... + ", " + d2.getFullYear() in the beginDay or endDay constructor if you want the date to appear with the year as in: Thurs., Jan. 6, 2011 - Wed., Jan. 12, 2011 -->
|