|
Q1130 How can I display all Sunday - Thursday dates in a list for the entire current year?
irt.org | Knowledge Base | JavaScript | Date | Q1130 [ previous next ]
Q1130 How can I display all Sunday - Thursday dates in a list for the entire current year?
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
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.