cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
calvares
Continued Contributor
Continued Contributor

Validation on date picker not working

For my booking app there are dates in the year that the service does not run on, such as weekends, Christmas holidays and UK Bank holidays. 

For validation, I added the following to the OnVisible property of the date picker's error message:

If(And(!IsBlank(DataCardValue21.SelectedDate),Or(Weekday(DataCardValue21.SelectedDate, StartOfWeek.Sunday) = 1, Weekday(DataCardValue21.SelectedDate, StartOfWeek.Sunday) = 7,DataCardValue21.SelectedDate <= Today(), (DataCardValue21.SelectedDate in "5/3/2021"), (DataCardValue21.SelectedDate in "5/31/2021"), (DataCardValue21.SelectedDate in "31/05/2021"), (DataCardValue21.SelectedDate in "8/30/2021"), (DataCardValue21.SelectedDate in "30/08/2021"), DataCardValue21.SelectedDate in colChristmas )), true, false)

The next card is Direction of travel and for this DisplayMode is set to: 

If(ErrorMessage18.Visible, DisplayMode.Disabled, DisplayMode.Edit)

So essentially the user shouldn't be able to proceed further if any of these dates come up. For specific dates, I had to add the selected date in two formats - both "m/dd/yyyy" and "dd/mm/yyyy". 

 

The app is live and I've had no problems with weekends, but for bank holidays, the specific dates some users have still been able to book on.  In all my testing no one has been able to book for bank holidays with the two date formats. However, for the date 30 August 2021, some users were able to book this and I can't work out why. Has anyone got any ideas?

9 REPLIES 9
PG_WorXz10
Resident Rockstar
Resident Rockstar

Hi @calvares ,

 

Is it because of the timezone difference ? Like user in there timezone selected previous day but it ended up on the holiday date due to timezone difference ? 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

calvares
Continued Contributor
Continued Contributor

Hi @PG_WorXz10 

That's interesting. So all the users should be in the UK so the same timezone, unless their devices are set to another one.

They wouldn't have selected the Sunday as they'd know the service doesn't run then, but they may have selected a Tuesday. But surely if they did select the Tuesday (today), it would have saved as that date on the system?

Hi @calvares ,

 

Is your data source is also in same region ? 

You can test it to check the date and time field storing date and time is correct format or if there is any deviation. 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

calvares
Continued Contributor
Continued Contributor

Yes, the data source is in the same region.

So under My Account settings for O365 I changed the time zone to UTC +12 and tested out some dates. The date saved as booked. I also updated my PC time zone and it was as expected too.

 

If the time zone was an issue then surely there would be bookings made at weekends, which isn't happening.

Is there anything else I could try?

Hi @calvares ,

 

Are you able to check the time of the data submitted ? 

The difference between Your time zone and UTC is only 30 mins. From the code you are checking the weekday and  with a slight difference in the timezone of the selected date the weekday calculation will change ? 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

calvares
Continued Contributor
Continued Contributor

Do I need to check the time of the data submitted in a different time zone? In my time zone, the time of the data submitted matches.

I don't quite understand how the calculation can change for someone who has a different time zone on their device/account. Could you explain in a bit more detail? Thank you.

calvares
Continued Contributor
Continued Contributor

I'm wondering if I also need to put the dates in other formats? So all the formats listed here: DateValue, TimeValue, and DateTimeValue functions in Power Apps - Power Apps | Microsoft Docs

If so I think I'll need to create a collection with all the different dates and formats. Or perhaps I could convert the selected date to a text string with a specific format then use that in my if statement instead? 

Hi @calvares ,

 

I would suggest storing the date in same format independent of the local datetime format and if there are users from different timezone it would be best if you convert all datetime into UTC so all datetime value will have same timezone. 

 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

SafaK
Helper I
Helper I

If the backend is Dataverse, then try to change the DateTime field property into "Time Zone Independent" instead of User local 

SafaK_0-1631173311978.png

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,242)