You are here: irt.org | FAQ | JavaScript | Date | Q1130 [ previous next ]
Try:
<script language="JavaScript"><!--
now = new Date()
CurrentYear = now.getYear()
if (CurrentYear < 1000) CurrentYear += 1900;
StartOfYear = new Date(CurrentYear,0,1);
StartDate = StartOfYear.getTime();
EndOfYear = new Date(CurrentYear,11,31);
EndDate = EndOfYear.getTime();
aDay = 1000*60*60*24;
text = 'Sundays through Thursdays in ' + CurrentYear;
for (var d = StartDate; d < EndDate; d+=aDay) {
theDate = new Date(d);
if (theDate.getDay() >= 0 && theDate.getDay() <= 4) {
if (theDate.getDay() == 0) text += '-</br>';
text += theDate.getDate() + '/' + (theDate.getMonth()+1) + '/' + theDate.getYear() + '<br>';
}
}
document.write(text);
//--></script>There are more date articles at http://irt.org/articles/script7.htm