Show Element Based On Date

Hey all,

I’m hoping someone can help me with this, I’ve spent about a week trying to solve this little puzzle and now I just can’t figure out what I’m doing wrong. I have a live-event website, where guests can post things from the event when it’s over (photos, videos, comments, etc.), and I have a little pop-up that I want to appear if people are visiting the event page on the same day as the event itself. So it would pop up and say “Still at the event?” And there would be a place for them to enter their email for us to remind them to come back the next day and post about it.

So my code is trying to compare today’s date with the date of the event, which is displayed on an existing element in the event page (shown below as “eventDateRead”, and it is a date picker element ). And if the dates match, the little pop-up would show. But it doesn’t seem to be working.

Here’s the code:

 let todaysDate = new Date();

    if ($w("#eventDateRead").value == todaysDate) {
        $w('#guestReminderForm1').show()
    }

I have a feeling the problem is something to do with the date format in the “new Date()” part, perhaps with it not matching the format of the date picker element. But I’m not sure how to correct that, or if there’s a simpler way to be doing this. I even tried adding another date picker and setting its value to todaysDate, and then making the comparison between the two date picker values, but that still didn’t work. The two date pickers showed the exact same date on the page, but it still didn’t display the pop-up.

Any help is greatly appreciated!

-Jared

Hi @jbelt40 ,

I would recommend to convert string value from input into date object (so it is the same format as new Date()) .

Does it solve your questions?

Certified Code