@mmaazkhanhere
Posted
It would be really helpful if someone can help me how to calculate age correctly including leap years and 30 31 day variations. I tried but couldnt get it correctly
@Hoodie1309
Posted
@mmaazkhanhere Hello. My solution for this problem:
const date = new Date(); const actualYear = date.getFullYear(); const actualMonth = date.getMonth() + 1;
const getDays = (year, month) => { return new Date(year, month, 0).getDate() }
const days = getDays(actualYear, actualMonth);
const days will return 30 or 31 and this const days you must use in your conditional if statement.
if it is not clear write and I will try to explain :)