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

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

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

<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?'

©2018 Martin Webb