Little help with js code

Trying to do a simple age calculator,for some reason the code can’t recognise the birthDay field from the database,although it is written exactly as it is.

Can anyone point me in the right direction?

I got a datepicker user input for the birthday part and a text for the age box display,both connected to the database

import wixData from "wix-data";

$w.onReady( async function () {
 
 var dobms = $w("#dataset1").birthDay.value.valueOf();       
 var nowms = Date.now();
 var age = Math.floor((nowms - dobms) / (365.25 * 24 * 60 * 60 * 1000));
    $w("#ageBox").text = age.toString();
});

Thank you

Hi Bilalayad,

In order to get an item from a dataset you can use the getItems() function of the dataset api. See examples here:
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getItems

Alternatively, you can get it directly from the collection itself, for example:

wixData.query("<your collection name>").find().then((results) => {
 
 // gets birthDay column from first row in the collection
 let dobms = results.items[0].birthDay; 
 console.log(dobms);
});

Good luck,
Asaf