Connect database to js Date [solved]

$w.onReady( () => {
  $w("#dynamicDataset").onReady( () => {
 let itemObj = $w("#dynamicDataset").getCurrentItem();
 let val = itemObj.AuctionEnd;
  } );
} );
let countDownDate = new Date("val").getTime();

Hi everyone.

I am trying to receive a “date and time” from the database and then use that for my countdown.

The variable that contains the data is “val” but when I connect it to my “countDownDate”, an NA shows up in preview.

How can I connect my “val” to Date()?

Thanks!

nevermind got it

He Melia, I’m trying to do the same thing. Would you mind posting your code on here?

of course!! here is my code:

// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixWindow from 'wix-window';

//Add the following to the top of your code to import wixData:
import wixData from 'wix-data';

$w.onReady(function () {
 //TODO: write your page related code here...
    console.log("onReady");

    $w('#group1').show();
        console.log("group 1 show");
 if (wixWindow.rendering.env === 'browser' || wixWindow.viewMode === 'Preview') {
 // only when in Front End so we get the user's local time (and not the server time)
 // otherwise, the display "flashes" - first the server's rendering, and then the local rendering

        console.log("frontend");

         $w("#dynamicDataset").onReady( () => {
        console.log("dynamic dataset");
 let itemObj = $w("#dynamicDataset").getCurrentItem();
        console.log("item obj"+JSON.stringify(itemObj));
 let val = itemObj.auctionEnd;
 let countDownDate = new Date(val).getTime(); // Countdown date and time
        console.log("val "+val);

 let countdown = setInterval(function () {
            console.log("countodnw");
 let now = new Date().getTime();
 let timeLeft = countDownDate - now; //big brain content that i stole haha
 let days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
 let hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
 let minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
 let seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);

            $w("#days").text = "" + days;
            $w("#hours").text = "" + hours;
            $w("#minutes").text = "" + minutes;
            $w("#seconds").text = "" + seconds;

 if (timeLeft > 0) {
            } else {
                clearInterval(countdown);
            }
        }, 1000);
         } );
 
    }
});

the countdown math came form here : https://www.wix.com/corvid/forum/community-discussion/example-countdown

hope this helps!

if i remember right, the main issue was a spelling error and MAYBE where the code was placed

Hey Melia,

Thanks so much for your reply. I’ve tried to use your code in combination with mine but I can’t seem to get it to work. Any chance you could take a look? Like you, I’m trying to replace the date with a date field in my database, which is conveniently labeled “date”.

Sorry for the late reply… If you still want me to, I’d be happy to take a look

@amelia3308 Hey! So I’ve just this second managed to work it out! I’m so happy! It was your code that allowed me to do it, so thank you so much!