Automatic redirect in the holiday period

Hello, I have the following problem:

The vacation is written into the cms (vacationDB) via a “set_vacation” page via 2 input fields (vacationStart & vacationEnd) and a “save vacation” button. This works.

But now I would like to read out the vacation period on the start page of the website: if today’s date is >= vacationStart AND <= vacationEnd → then I want to redirected to another page “Show vacation period to the webSite users” .

I have the following script for this, but unfortunately it doesn’t work…

//

<script type="text/javascript">
$w.onReady(function () {
    const vacationUrl = "/coming-soon-01";

    wixData.query("vacationDB") 
        .find()
        .then(function(results) {
            if (results.items.length > 0) {
                const vacationPeriod = results.items[0];
                const today = new Date();

                if (today >= vacationPeriod.vacationStart && heute <= vacationPeriod.vacationEnd) {
                    wixLocation.to(vacationUrl);
                }
            }
        })
        .catch(function(error) {
            console.log(error);
        });
});
</script>


Can anybody help me?
 thx Manfred

Hello, I have the following problem:

The vacation is written into the cms (vacationDB) via a “set_vacation” page via 2 input fields (vacationStart & vacationEnd) and a “save vacation” button. This works.

But now I would like to read out the vacation period on the start page of the website: if today’s date is >= vacationStart AND <= vacationEnd → then I want to redirected to another page “Show vacation period to the webSite users” .

I have the following script for this, but unfortunately it doesn’t work…

//

Can anybody help me?
thx Manfred

Hey @Manfred1!

When using Velo, there’s no need to wrap your code in a script.

$w.onReady(function () {
    const vacationUrl = "/coming-soon-01";

    wixData.query("vacationDB") 
        .find()
        .then(function(results) {
            if (results.items.length > 0) {
                const vacationPeriod = results.items[0];
                const today = new Date();

                if (today >= vacationPeriod.vacationStart && heute <= vacationPeriod.vacationEnd) {
                    wixLocation.to(vacationUrl);
                }
            }
        })
        .catch(function(error) {
            console.log(error);
        });
});

The code seems to be fairly accurate, although I haven’t tested it myself.

I do see you using heute, although I’m not seeing where this is coming from. I believe it should also say today.

Let us know how you get on :slight_smile: