Date showing one date behind in different time zone

Hi Wix team,

I had a client try to book on to one of my course but kept insisting that the date he was looking for wasn’t listed, after some emails back and forth and nearly loosing the client, I sent a screen shot which seemed to puzzle him, the dates showing for me and what’s in my database was on my screen (UK) but on his screen (US) it was showing one date behind, he changed his time zone and it solved the display issue. This obviously needs fixing but it only recently become highlighted and I have never had a problem before, not sure if it’s anything to do with wix turbo??

Anyway, here is my code to show the dates

export function radioGroup2_change(event) {
let itemObj =$w("#dynamicDataset").getCurrentItem();
 if ($w("#radioGroup2").value === "1") {
        $w('#date1').text = itemObj.dateOneYh.toDateString();
        $w('#date2').text = itemObj.dateTwoYh.toDateString();
        $w('#date3').text = itemObj.dateThreeYh.toDateString();
        $w('#date4').text = itemObj.dateFourYh.toDateString();
        $w('#date5').text = itemObj.dateFiveYh.toDateString();
        $w('#date6').text = itemObj.dateSixYh.toDateString();
        BookNowButtonENABLETwo()
        checkAvalibilityTwo()
        checkAvalibilityOneDisable()
    }
 else if ($w("#radioGroup2").value === "2") {
        $w("#date1").text = itemObj.dateone.toDateString();
        $w("#date2").text = itemObj.dateTwo.toDateString();
        $w("#date3").text = itemObj.datethree.toDateString();
        $w("#date4").text = itemObj.dateFour.toDateString();
        $w("#date5").text = itemObj.dateFive.toDateString();
        $w("#date6").text = itemObj.dateSix.toDateString();
        BookNowButtonENABLEOne()
        checkAvalibilityOne()
        checkAvalibilityTwoDisable()
    }
});

Also, here is a link to on of the dynamic pages https://www.scottishrockandwater.com/Courses/Scrambling/Aonach-Eagach-Guided-Traverse

Thanks

Stephen

I have been doing some research and had some help from the Facebook pages but still seem to be struggling with this. I have adjusted my code after reading an article on Date.toLocaleDateString() and some variations, which all adjust the format for the users timezone but it doesn’t retain the date which is in my database. I could really do with a little help with this one as all of my start dates are one day out if not viewed in the UK!

That is because .toLocaleDateString uses the default local data on the device.

Try this code to check the output:

// America/Los_Angeles for the US
// US English uses month-day-year order

date.toLocaleDateString('en-US');
//or
date.toLocaleDateString('en-US', options)
// → "12/19/2012"


// British English uses day-month-year order

date.toLocaleDateString('en-GB');
//or
date.toLocaleDateString('en-GB', options)
// → "20/12/2012"

Have a look at these pages if you haven’t done already:

Hey @givemeawhisky , thanks for the info. I’ve had a look at the documents a few days ago and played with the code, to mu knowledge the code adjusts (as you mentioned in your code above) the format of the date, but the issue I’m having is that the date is changing to the time zone. The pictures below are form the same trip, but I have changed the time zone on my computer.


Dates with UK time zone


Dates with US time zone

Hopefully it’s possible to show the date that’s in my database, regardless of the users timezone?

@yisrael-wix @yoav-wix can you guys shed any light on this one? I have a sinking feeling this has been this way since I started the website when Wix code was first introduced. I basically only want the date that’s in my database (UK) to show regardless of the users timezone. From research I know that in java dates will be adjusted to the timezone of the user, but how to I stop this happening?
I have noticed that when i change the timezone on my computer it also adjusts the dates in the database…
Thank you in advance

It may be because the server time/date is being used as opposed to the local (browser) time/date. Also, sometimes it depends on how you retrieve that date and time from the Date() object.

See the Open for Business example - it seems to show the correct date and time.

I hope this helps.

Hi Stephen, did you ever solve this?
I’m having the exact same issue and cannot seem to find a solution anywhere.

@yisrael-wix , the template in the example you linked is not available. Could you please write the solution here?

Hi @stefanroi ,

The issue was solved, but I had to pay someone. Turns out it was quite complex, I had no chance! I can pass on details if it helps?

That’s bad news - I like to know my site (and code). But I would love to have the details as a last resort, thanks. How much did it cost you?

Hi Stephen,
Thank you for raising this issue. I’m also experiencing the same issue. The date in the collection is shown 1 day before when using " toLocaleDateString(‘en-UK’, options)" for displaying to the user. Can you please mail me the solution code to avn.solsys@gmail.com

I’m scrambling a lot and seems like my head will blast.

@stephenmccall Please help

Hi @avshrss , I was able to get in touch with Stephen and actually hired him to make the fix for me. I don’t know if he’s available for new gigs or not, but I HIGHLY recommend him. He was awesome!

Not sure if maybe this helps:

Hello everyone, has this been solved? I’m facing the same issue and its causing a lot of confusion in my databases. OP said he paid someone to fix this. It was somebody on Wix? An external developer?