Reylin Mathew

Reylin Mathew

  • NA
  • 347
  • 75.3k

how to age and month from date

Jul 17 2021 2:19 PM

Age calculation

DOB = 2010-07-01(July)

DATE = 2026-08-01 (August)

correct age is  = 15 yrs 11 mnths

but this code returns = 16 yr 1 mnt..

my code attached also,

  

var age = retoday.getFullYear() - dob.getFullYear();
        var mnth = 0;
        if (today.getMonth() == 0) {
            mnth = (today.getMonth() + 1) - dob.getMonth();
        }
        else
            tmnth = today.getMonth() - dob.getMonth();
        if (tmnth < 0 || (retmnth == 0 && (today.getDate() < dob.getDate()))) {
            tage--;
        }

 

plz hlp me...thnkx in adv

 

 


Answers (2)