javascript - how to deal with dates 6 months ahead if year increments -


here function, trying date 6 months ahea, or 6 months before.

  var newenddate = formatdateaddmonths(startdate,+6);   function formatdateaddmonths(datemod, monthsaddeddeducted)        {             //startdate            //split date            var datesplit = datemod;            var datesplitted = datesplit.split("/");            var day = datesplitted[0];            var month = datesplitted[1];            var year = datesplitted[2];             console.log("day" + day);            console.log("month" + month);            console.log("year" + year);             newdatemodification = day + '/' + month + '/' + year;            var newdate = date.parse(newdatemodification).add(monthsaddeddeducted).months();            //convert string            var newdatestring = newdate.tostring('dd/mm/yyyy');            return newdatestring;        } 

this works fine long function not called before end of year.

it breaks example if startdate = 10/11/2015 because year not incremented, date end being 29/12/2015

date.parse(newdatemodification).add(monthsaddeddeducted).months();  

is date.js function

any idea how deal year increments?

thanks.

if use function similar to

normalizemonths( datestring ){     var split = datestring.split("/");     if ( split[1] > 12 ){         split[1] = split[1] - 12;         split[2] = split[2] + 1;     } 

and reassemble date did before, should fix it.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -