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

Q268 How do I work out the date seven days before a text string mm/dd/yy?

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

Q268 How do I work out the date seven days before a text string mm/dd/yy?

<SCRIPT LANGUAGE="JavaScript"><!--
function week_before(s) {
    // parse s for month, day, year
    var dateArray = s.split('/');
    sdate = new Date(dateArray[2],dateArray[0]-1,dateArray[1]);

// figure out day, month, year 7 days ago
    var odate = new Date(sdate.getTime() - (7 * 86400000));

// return value
    return (odate.getMonth()+1) + '/' + odate.getDate() + '/' + odate.getYear();
}

var date_7_days_ago = week_before("4/9/98");
alert(date_7_days_ago);
//--></SCRIPT>

Feedback on 'Q268 How do I work out the date seven days before a text string mm/dd/yy?'


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.