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>