web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Date Calculation Incor...
Power Apps
Unanswered

Date Calculation Incorrect During Patch() Formulas in Published Mode

(0) ShareShare
ReportReport
Posted on by 473

I have a Patch() function that create 1 parent 'Reservation' record, and multiple child 'Reservation Details' records, and it skips weekends and a collection of holiday dates.

When I am executed Patch() function in Editing mode, both 'Reservation and 'Reservation Details' records were created on the correct days (weekdays).

However, when the app is published, 'Reservation Details' records created there was incorrect (1 day behind).

Scenario

- FromDate_Datepicker : Mon (05 Feb 2024)
- ToDate_Datepicker = Sun (11 Feb 2024)

 05 Feb06 Feb07 Feb08 Feb 09 Feb10 Feb11 Feb
 MonTueWedThuFriSatSun
Editing ModeCreatedCreatedCreatedCreatedCreatedSkippedSkipped
Published ModeSkippedCreatedCreatedCreatedCreatedCreatedSkipped
Published Mode is 1 day behind*Sun*Mon*Tue*Wed*Thu*Fri*Sat


Based on the results above, Published Mode is 1 day behind Editing Mode.

Question: May I know how can I resolve this, and is a code change to fix this possible?

Thank you.
_____________________________________________________________________________________

Below is my full Patch() function:

 

//Creates 1x parent 'Reservation' record
If(
 BookingType_Self_Cb.Checked,
 ClearCollect(
 ReservationRecord,
 Patch(
 Reservations,
 Defaults(Reservations),
 {
 'Start Date': FromDate_Dp.Value,
 'End Date': ToDate_Dp.Value,
 'Reserved For': 'Reserved For (Reservations)'.Employee,
 Facility: Building_Ddl.Selected,
 Area: Area_Ddl.Selected,
 'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
 'Reserved Desk': Self_Section_Seat_Ddl.Selected,
 'Booked By': Self_Section_EmployeeName_Ddl.Selected
 }
 )
 )
);
// Store created parent 'Reservation' record in a variable 'newReservationRecord'
Set(
 newReservationRecord,
 First(ReservationRecord)
);

//Create 'Reservation Details' record for each date and associated it with 'Reservation' record created by 'Reservation Details'.'Reservation'
//Only create records if date matches weekdayt dates in WeekdayDates collection
Patch(
 'Reservation Details',
 ForAll(
 Sequence(
 DateDiff(
 FromDate_Dp.Value,
 ToDate_Dp.Value,
 TimeUnit.Days
 ) + 1
 ),
 With(
 {
 _Date: DateAdd(
 FromDate_Dp.Value,
 Value - 1,
 TimeUnit.Days
 )
 },
 If(
 _Date in WeekdayDates,
 {
 Date: _Date,
 Reservation: newReservationRecord,
 Name: newReservationRecord.'Reservation ID' & "_" & _Date,
 'Reserved Desk': newReservationRecord.'Reserved Desk'
 }
 )
 )
 )
);

 

 
- 'Reservations'.'Start Date' is correct
- 'Reservations'.'End Date' is correct
- 'Reservation Details'.'Date' is wrong

Categories:
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @gymcode 

     

    can u please try this modified version:

    // Creates 1x parent 'Reservation' record
    If(
     BookingType_Self_Cb.Checked,
     ClearCollect(
     ReservationRecord,
     Patch(
     Reservations,
     Defaults(Reservations),
     {
     'Start Date': FromDate_Dp.SelectedDate,
     'End Date': ToDate_Dp.SelectedDate,
     'Reserved For': 'Reserved For (Reservations)'.Employee,
     Facility: Building_Ddl.Selected,
     Area: Area_Ddl.Selected,
     'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
     'Reserved Desk': Self_Section_Seat_Ddl.Selected,
     'Booked By': Self_Section_EmployeeName_Ddl.Selected
     }
     )
     )
    );
    
    // Store created parent 'Reservation' record in a variable 'newReservationRecord'
    Set(
     newReservationRecord,
     First(ReservationRecord)
    );
    
    // Create 'Reservation Details' record for each date and associate it with 'Reservation' record
    Patch(
     'Reservation Details',
     ForAll(
     WeekdayDates,
     If(
     Value >= FromDate_Dp.SelectedDate && Value <= ToDate_Dp.SelectedDate,
     Collect(
     ReservationDetailsCollection,
     {
     Date: Value,
     Reservation: newReservationRecord,
     Name: newReservationRecord.'Reservation ID' & "_" & Value,
     'Reserved Desk': newReservationRecord.'Reserved Desk'
     }
     )
     )
     )
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • vaubeee Profile Picture
    533 on at

    @gymcode looks like you are reversing 1 day on purpose!? .... Value -1 🤔

     

     With(
     {
     _Date: DateAdd(
     FromDate_Dp.Value,
     Value - 1,
     TimeUnit.Days
     )
     },

     

     

    ------------------------------------------------------------------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

  • ruihaolrh Profile Picture
    473 on at

    Hi @mmbr1606 , thank you for the formula. I encountered some issues implementing it.

    1. My DatePicker control does not have '.SelectedDate'

    gymcode_0-1706272757030.png


    I will attempt other changes apart from the above.

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    try it that way:

     

    // Creates 1x parent 'Reservation' record
    If(
     BookingType_Self_Cb.Checked,
     ClearCollect(
     ReservationRecord,
     Patch(
     Reservations,
     Defaults(Reservations),
     {
     'Start Date': FromDate_Dp.Value,
     'End Date': ToDate_Dp.Value,
     'Reserved For': 'Reserved For (Reservations)'.Employee,
     Facility: Building_Ddl.Selected,
     Area: Area_Ddl.Selected,
     'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
     'Reserved Desk': Self_Section_Seat_Ddl.Selected,
     'Booked By': Self_Section_EmployeeName_Ddl.Selected
     }
     )
     )
    );
    
    // Store created parent 'Reservation' record in a variable 'newReservationRecord'
    Set(
     newReservationRecord,
     First(ReservationRecord)
    );
    
    // Create 'Reservation Details' record for

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • ruihaolrh Profile Picture
    473 on at

    Hi @mmbr1606, I changed my date controls to Modern control, and I am now able to see the .SelectedDate option.

    I have tried your modified code, but encountered an error as follow:

    gymcode_0-1706274746381.png

     

    // Creates 1x parent 'Reservation' record
    If(
     BookingType_Self_Cb.Checked,
     ClearCollect(
     ReservationRecord,
     Patch(
     Reservations,
     Defaults(Reservations),
     {
     'Start Date': FromDate_Dp.SelectedDate,
     'End Date': ToDate_Dp.SelectedDate,
     'Reserved For': 'Reserved For (Reservations)'.Employee,
     Facility: Building_Ddl.Selected,
     Area: Area_Ddl.Selected,
     'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
     'Reserved Desk': Self_Section_Seat_Ddl.Selected,
     'Booked By': Self_Section_EmployeeName_Ddl.Selected
     }
     )
     )
    );
    
    // Store created 'Reservation' record in a variable 'newReservationRecord'
    Set(
     newReservationRecord,
     First(ReservationRecord)
    );
    
    // Create 'Reservation Details' record for each date and associate it with 'Reservation' record
    Patch(
     'Reservation Details',
     ForAll(
     WeekdayDates,
     If(
     Value >= FromDate_Dp.SelectedDate && Value <= ToDate_Dp.SelectedDate,
     Collect(
     ReservationDetailsCollection,
     {
     Date: Value,
     Reservation: newReservationRecord,
     Name: newReservationRecord.'Reservation ID' & "_" & Value,
     'Reserved Desk': newReservationRecord.'Reserved Desk'
     }
     )
     )
     )
    );

     

  • ruihaolrh Profile Picture
    473 on at

    Let me try removing this, as the dates were correct when testing in Editing mode.

  • ruihaolrh Profile Picture
    473 on at

    I tried removing the '-1' and there was no 'Reservation Details' created, so I think it is needed.

  • ruihaolrh Profile Picture
    473 on at

    Hi @mmbr1606 , just to check if the bottom part of the formula was being cut off?

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    i posted a modification abvoe with the .Value option

     

    did u already try?

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at
    // Creates 1x parent 'Reservation' record
    If(
     BookingType_Self_Cb.Checked,
     ClearCollect(
     ReservationRecord,
     Patch(
     Reservations,
     Defaults(Reservations),
     {
     'Start Date': FromDate_Dp.Value,
     'End Date': ToDate_Dp.Value,
     'Reserved For': 'Reserved For (Reservations)'.Employee,
     Facility: Building_Ddl.Selected,
     Area: Area_Ddl.Selected,
     'Employee Name': Self_Section_EmployeeName_Ddl.Selected,
     'Reserved Desk': Self_Section_Seat_Ddl.Selected,
     'Booked By': Self_Section_EmployeeName_Ddl.Selected
     }
     )
     )
    );
    
    // Store created parent 'Reservation' record in a variable 'newReservationRecord'
    Set(
     newReservationRecord,
     First(ReservationRecord)
    );
    
    // Create 'Reservation Details' record for each date and associate it with 'Reservation' record
    Patch(
     'Reservation Details',
     ForAll(
     WeekdayDates,
     If(
     Value >= FromDate_Dp.Value && Value <= ToDate_Dp.Value,
     Collect(
     ReservationDetailsCollection,
     {
     Date: Value,
     Reservation: newReservationRecord,
     Name: newReservationRecord.'Reservation ID' & "_" & Text(Value, "[$-en-US]yyyy-mm-dd"),
     'Reserved Desk': newReservationRecord.'Reserved Desk'
     }
     )
     )
     )
    );

     

    looks like so, lol

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard