/ Published in: JavaScript
This function accepts a date string (yyyymmdd), along with a number of days (integer) and adds the days to the date. It then returns the new date string (yyyymmdd).
Expand |
Embed | Plain Text
function addToDate(date,days) { var yyyy,mm,dd,idate,newdate; date = String(date); yyyy = date.substr(0,4); mm = date.substr(4,2) - 1; dd = date.substr(6,2) - 0; idate = new Date(yyyy,mm,dd,0,0,0,0); idate.setTime(idate.getTime()+60000*60*24*days); yyyy = idate.getYear(); if (yyyy < 1000) yyyy += 1900; mm = idate.getMonth() + 1; if (mm < 10) mm = '0' + mm; dd = idate.getDate(); if (dd < 10) dd = '0' + dd; newdate = parseInt(String(yyyy) + String(mm) + String(dd)); return newdate; }
You need to login to post a comment.
