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

Q656 How can you write to the document both the Last Modified and a review date, i.e. Last Modified date plus 100 days?

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

Try:

<SCRIPT LANGUAGE = 'JavaScript'><!--
function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]; }

function getCorrectedYear(year) {
    year = year - 0;
    if (year < 70) return (2000 + year);
    if (year < 1900) return (1900 + year);
    return year;
}

var months = new makeArray('January','February','March','April','May','June','July','August','September','October','November','December');

function nths(day) {
    if (day == 1 || day == 21 || day == 31) return 'st';
    if (day == 2 || day == 22) return 'nd';
    if (day == 3 || day == 23) return 'rd';
    return 'th';
}

var modifiedDate = new Date(document.lastModified);

document.write('Last modified: ' + months[modifiedDate.getMonth() + 1] + ' ' + modifiedDate.getDate() + nths(modifiedDate.getDate()) + ' ' + getCorrectedYear(modifiedDate.getYear()));

var reviewDate = new Date(modifiedDate.getYear(),modifiedDate.getMonth(),modifiedDate.getDate() + 100);

document.write('<P>Review date: ' + months[reviewDate.getMonth() + 1] + ' ' + reviewDate.getDate() + nths(reviewDate.getDate()) + ' ' + getCorrectedYear(reviewDate.getYear()));
//--></SCRIPT>

©2018 Martin Webb