# Need help with Age Calculator

**URL:** <https://forum.wixstudio.com/t/need-help-with-age-calculator/33988>\
**Category:** Ask the community\
**Tags:** design, code, question\
**Created:** [October 4, 2022, 7:53am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988 "2022-10-04T07:53:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesurcan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/cesurcan/32/24205_2.png) [@cesurcan](https://forum.wixstudio.com/u/cesurcan)\
**Post date:** [October 4, 2022, 7:53am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/1 "2022-10-04T07:53:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 4, 2022, 8:01am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/2 "2022-10-04T08:01:06Z")

</div>

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

```

Works?

---

<div class="post-metadata">

**Author:** ![cesurcan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/cesurcan/32/24205_2.png) [@cesurcan](https://forum.wixstudio.com/u/cesurcan)\
**Post date:** [October 4, 2022, 8:05am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/3 "2022-10-04T08:05:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 4, 2022, 8:30am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/4 "2022-10-04T08:30:35Z")

</div>

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 ??

> **[Video: Introduction to Moment.js | Velo by Wix](https://community.wix.com/velo/forum/tips-tutorials-examples/video-introduction-to-moment-js)**
>
> Karen from the Developer Relations team shows you how to install the Moment.js NPM package and walks through a few simple examples to show the differences between manipulating dates with JS vs Moment.
> 
> Have you worked with Moment before? What's your...

Maybe you want to learn more about it.

Or you go traditional way…

> **[Code for the time difference in hours in a time picker | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/code-for-the-time-difference-in-hours-in-a-time-picker)**
>
> Hello, I'm new to coding, and I'm stuck when trying to find the time difference (between the current time and the userinput in a time picker). Specifically, I want when a user changes the time in a time picker, the difference in hours between the...

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

> **[Code for the time difference in hours in a time picker | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/code-for-the-time-difference-in-hours-in-a-time-picker)**
>
> Hello, I'm new to coding, and I'm stuck when trying to find the time difference (between the current time and the userinput in a time picker). Specifically, I want when a user changes the time in a time picker, the difference in hours between the...

> **[\[SOLVED\] How to add an hour (or more) to timepicker value? | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/how-to-add-an-hour-or-more-to-timepicker-value)**
>
> Hi everyone, is there a way to change the value of a timepicker to any number of hours, minutes and
> Seconds to add?
> 
> Here's an example:
> 
> Someone decides to attend an event. The event starts at 8 am and lasts approximately 1.5 hours. I would now like...

---

<div class="post-metadata">

**Author:** ![cesurcan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/cesurcan/32/24205_2.png) [@cesurcan](https://forum.wixstudio.com/u/cesurcan)\
**Post date:** [October 4, 2022, 8:56am UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/5 "2022-10-04T08:56:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 4, 2022, 1:49pm UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/6 "2022-10-04T13:49:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cesurcan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/cesurcan/32/24205_2.png) [@cesurcan](https://forum.wixstudio.com/u/cesurcan)\
**Post date:** [October 4, 2022, 2:09pm UTC](https://forum.wixstudio.com/t/need-help-with-age-calculator/33988/7 "2022-10-04T14:09:22Z")

</div>

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