JavaScript Calculate what exact date it would be after exactly X Years -


now finding challenging exact date after 'x' years date (birth date), 'yyyy/mm/dd'

a trivial version be

function addyearstodate(date, years) {     return +date.slice(0, 4)+years + date.slice(4); } 

here, +date.slice(0,4) makes number out of first 4 characters of date, add number of years, concatenate remainder of input date.

> addyearstodate('1953/04/18', 62) < "2015/04/18" 

you need special-case feb. 29.

this assumes want input , output in string form yyyy/mm/dd. more sophisticated date manipulation, consider using library moment allow things like

moment('1953/04/18').add(62, 'years') 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -