#  Coding with Velo API

**URL:** <https://forum.wixstudio.com/t/coding-with-velo-api/9835>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [November 26, 2022, 1:40am UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835 "2022-11-26T01:40:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zogbea](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@Zogbea](https://forum.wixstudio.com/u/Zogbea)\
**Post date:** [November 26, 2022, 1:40am UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/1 "2022-11-26T01:40:00Z")

</div>

I want my users to choose their age before register. If the age is under 18( want the return to be ‘False’ ) Else (‘true’).  
So, the problem is how to run this code to automatically detect that user input age is under 18. I search Velo APIs and database properties, can’t find anything. Only property closed, is the date of the creation or update which is available in my data collection properties. Any help?

---

<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:** [November 26, 2022, 12:44pm UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/2 "2022-11-26T12:44:54Z")

</div>

You may want to use → “Custom-Fields” during registration process…

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/c/8ca2286e56f4e2951f5cc31d663793802198dcfc.png)

---

<div class="post-metadata">

**Author:** ![Zogbea](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@Zogbea](https://forum.wixstudio.com/u/Zogbea)\
**Post date:** [November 26, 2022, 6:26pm UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/3 "2022-11-26T18:26:13Z")

</div>

I am using custom field. The problem is how to run this code to automatically detect that user input age is under 18. I search Velo APIs and database properties, can’t find anything.  
Any example ?

---

<div class="post-metadata">

**Author:** ![Zogbea](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@Zogbea](https://forum.wixstudio.com/u/Zogbea)\
**Post date:** [November 26, 2022, 10:15pm UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/4 "2022-11-26T22:15:29Z")

</div>

This is my Code but not running. Always returning console in after “else”

![](https://us1.discourse-cdn.com/wix/original/3X/7/a/7aaa5536932c11660ced0d7d3160870ad3c17fc5.jpeg)

---

<div class="post-metadata">

**Author:** ![Zogbea](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@Zogbea](https://forum.wixstudio.com/u/Zogbea)\
**Post date:** [November 27, 2022, 12:24am UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/5 "2022-11-27T00:24:53Z")

</div>

I find a way to do run my code and it now running perfectly. After registration button show, I can now call the API “Authentication” to\_Register the user. Thank you All.

```
                                                            **let** date = $w ( "#datePicker1" ). value ; 

                                                            **var** todaysDate = **new** Date (). getFullYear (); //Current year 
                                                            **let** inputDate = $w ( "#datePicker1" ). value ; //Value from date picker 

                                                            **var** inputDateYear = inputDate . getFullYear (); 

                                                            $w ( "#alerterms1" ). text = 'Your age is:' + String ( todaysDate - Number ( inputDateYear )) + 'years' 

                                                            **let** age = String ( todaysDate - Number ( inputDateYear )) 
                                                            console . log ( age ) 
                                                            **let** minimum = 1000 * 18 * 365 * 60 * 60 * 24 
                                                            **if** (( todaysDate - Number ( inputDateYear )) > 18 ) { 
                                                                $w ( "#registrationButton" ). show (); 
                                                                console . log ( 'User have the minimum age' ) 
                                                                $w ( "#loading" ). show (); 

                                                            } **else** { 
                                                                // WHY I GET THIS RESULT ANYWAY ?????????? 
                                                                console . log ( 'User does not have the minimum age' ) 
                                                                $w ( "#alerterms1" ). text = ' You have to be 18 years old to use proceed' 
                                                            }

```

---

<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:** [November 27, 2022, 12:54pm UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/6 "2022-11-27T12:54:29Z")

</div>

Calculation of dates and times should be done by using → “timestamps”

You even get an error here…

![](https://us1.discourse-cdn.com/wix/original/3X/d/3/d3fc462c897b392b80ca5db70a5b4539548958d3.png)  
Because such a calculation is not doable.

Break everything down to timestamps…

```javascript
$w('#datePicker1').onChange(()=>{
    let today = new Date();
    let todayTimeStamp = (new Date(today)).getTime(); 
    console.log("Timestamp-Today: ", todayTimeStamp);
    let date = $w('#datePicker1').value;     
    console.log("Date: ", date);
    let userTimeStamp = (new Date(date)).getTime(); 
    console.log("Timestamp by User: ", userTimeStamp);
    let resultingTimestamp = userTimeStamp-todayTimeStamp; 
    console.log("ResTimestamp: ", resultingTimestamp);
});

```

And then convert back from timestamp to date and time.

This way you will be able to calculate Dates & Time.

---

<div class="post-metadata">

**Author:** ![Zogbea](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@Zogbea](https://forum.wixstudio.com/u/Zogbea)\
**Post date:** [November 27, 2022, 3:26pm UTC](https://forum.wixstudio.com/t/coding-with-velo-api/9835/7 "2022-11-27T15:26:57Z")

</div>

Thank you very much ! Grateful !
