Adding years to date of birth decrements the month by one.
Adding years to date of birth decrements the month by one.
Glyndwr
Posts: 128Questions: 35Answers: 1
I am adding eight years to the date of birth; however, when I do this the month decrements by one (i.e., 16/10/2010 + 8 = 16/9/2018 and 16/1/2010 + 8 = 16/0/2018).. I can get round this by adding 1 to the month. However, I am concerned that this may cause other issues. The code is:
{"data": null, //data is null since we want to access ALL data for the sake of our calculation below
"render": function(data,type,row) {
var DOB = new Date(data.dob);
var year = DOB.getFullYear() + 8;
var month = DOB.getMonth() + 1;
var day = DOB.getDate();
return (day + "/" + month + "/" + year);
},
},
Also, I would like the answer returned as dd/mm/yyyy rather than d/m/yyyy.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @Glyndwr ,
The best bet with anything date/time related is to use Moment.js, it'll make it far easier.
Cheers,
Colin
@colin , this is so much easier:
Thank you.