Code not working properly

my current code is not working. It does not take me to the about page.

import wixLocation from ‘wix-location’;

$w.onReady(function () {
const redirectDate = new Date(‘2023-05-04T20:20:00’);

$w('#button15').onClick(() => { 
    if (Date.now() >= redirectDate.getTime()) { 
        wixLocation.to('/birdiesandbourbon/about'); 
    } else { 
        wixLocation.to('/birdiesandbourbon/sorry'); 
    } 
}); 

});

test —> console.log(Date.now());
test —> console.log((new Date(‘2023-05-04T20:20:00’).getTime():wink:

What result do you get for both?

only goes to the site the button is linked to, so its like the code doesnt matter

If I unlink the button it doesnt do anything

No, no no! :joy:

When i giving you this…
test —> console.log(Date.now());
test —> console.log((new Date(‘2023-05-04T20:20:00’).getTime():wink:

…it does not mean that you implement it directly like it is into your code, like this…

$w.onReady(()=> {console.log("Page ready...");
    ---> console.log(Date.now());
    ---> console.log((new Date('2023-05-04T20:20:00').getTime()));
});

That’s a → NO-GO !!! That of course will not work, since it is not a conform JS-Syntax.

You have to implement it with the right JS-Syntax, like the following…

$w.onReady(()=> {console.log("Page ready...");
    console.log(Date.now());
    console.log((new Date('2023-05-04T20:20:00').getTime()));
});

And your whole code, looks like…

import wixLocation from 'wix-location';

$w.onReady(()=> {console.log("Page ready...");
    //console.log(Date.now());
    //console.log((new Date('2023-05-04T20:20:00').getTime()));

    const redirectDate = new Date('2023-05-04T20:20:00');
    console.log("Redirect-Date: ", redirectDate.getTime());
    console.log(Date.now());

    $w('#button15').onClick(() => {console.log("Clicked");
        if (Date.now() >= redirectDate.getTime()) {console.log("GO-IF");
            wixLocation.to('https://www.google.com');
        } else {console.log("GO-ELSE");
            wixLocation.to('/birdiesandbourbon/sorry');
        }
    });
});

I tested your code, changing it’s URL and it works.
Take a look onto this example and try again.

!!! Good luck and happy coding !!!

Code-Ninja

still only goes to sorry page. even with the time and date function saying it should go to about page at this time

blob:https://community.wix.com/2169e5f1-ef8a-43f7-bfe3-fa480fd1988f

Still doesnt work. Only goes to the sorry page. time and date code not formulating it to go to the about page