Need help with Age Calculator

Hello everyone. I created a date picker and coded a age calculator in velo.

$w . onReady (() => {
$w ( “#datePicker” ). onChange (() => {

    **var**  todaysDate  =  **new**  Date (). getFullYear (); // CURRENT YEAR 

    **let**  inputDate  =  $w ( "#datePicker" ). value ; //VALUE FROM DATE PICKER 
    **var**  inputDateyear  =  inputDate . getFullYear (); //YEAR PICKED FROM DATE PICKER 

    $w ( "#textElementID" ). show (); //SHOW TEXT AFTER PICKING A DATE (OPTIONAL) 

    $w ( "#textElementID" ). text  =  `Çocuğunuz " ${ String ( todaysDate  -  Number ( inputDateyear ))} " yaşında.` ;  //DESIGN YOUR MESSAGE 

}) 

})

this is my current code. When user selects a date, it will show “you are … years old.”

But i want to convert it to = “you are … years, … months, … days old.”

How can i convert it? Can you guys help me?

$w("#textElementID").text = `Hey, you are ${String(todaysDate - Number(inputDateyear))} days old.`;

Works?

Nope, it still only says hey, you are for example 4 years old when i choose 2018. I want to convert it to = for example, “You are 4 years, 5 months and 20 days old”. I want to add month and days to it. Thanks for quick response!

Ok, now i understood your problem.

You have problems to work with TIME and DATES, like the most right?

Already heard something about MOMENT-NPM ??

Maybe you want to learn more about it.

Or you go traditional way…

see following posts and learn the handling with dates and times)…

Thanks for the reply. Actually i just need to take month and day from the date picker to show result as you are … years … months and … days old. Is there a couple code that i can add it? Thanks you again for having interest on this topic.

Maybe you will find here your solution…
https://www.wix.com/velo/forum/coding-with-velo/get-exact-age-from-datepicker

Checked out that topic but could not understand it. Maybe @yisrael-wix can help me out here :slight_smile: