Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Date | Q656 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.