Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1493 How can I make a drop down list of dates where the list will display dates in the format mm/dd/yy from today to 14 days before only (this is for a time sheet entry process where dates more than 2 weeks old cant be input)?

You are here: irt.org | FAQ | JavaScript | Date | Q1493 [ previous next ]

Try:

<form>
<script>
now = new Date()
aDay = 24*60*60*1000;
then = new Date(now.getTime()-(14*aDay));
text = '<select>';
for (i=then.getTime();i<now.getTime();i+=aDay) {
   date = new Date(i);
   year = date.getYear();
   if (year < 1900) year += 1900;
   dateString = (date.getMonth()+1)+'/'+date.getDate()+'/'+year;
   text += '\n<option value="' + dateString + '">'+ dateString+'</option>';
}
text += '</select>';
document.write(text);
</script>
</form>

©2018 Martin Webb