I created an app a while ago that display dates in a Data Picker field from a SQL Database table.
Demo: https://youtu.be/KwHTVjL_LBU
It took me quite a while to get the date value dispaying the correct info, especially pertaining to get the correct information displaying regardless of the timezone the app had been launched in.
Looking back now at the source code in that app for the Date Picker control I specified the following property values that collectively displayed the correct info across different time zones:
DateTimeZone: DateTimeZone.UTC
DefaultDate: If( IsBlank( activity_date_v ), DateAdd( Now(), - TimeZoneOffset(), Minutes ), attendance_date_v )
When editing an existing record the activity_date_v variable is set to the specific date saved in the SQL table, passed to the Add/Edit Form screen from the selected item gallery control in the preceeding screen in the app.
When adding a new record, obviously the default value for the Date Picker control is determed by the DefaultDate property, however what I can't exactly recall why (albeit that it must have been relevant), in the OnSelect property of the Date Picker control contains the following code:
If( DateDiff(
Activity_Date.SelectedDate;
attendance_date_v,
Days
) <> 0,
UpdateContext({ attendance_date_v: Activity_Date.SelectedDate })
);
UpdateContext({
attendance_date_v:
If( DateDiff(
Activity_Date.SelectedDate,
DateAdd( Now(), -TimeZoneOffset(), Minutes ),
Days
) < 0,
DateAdd( Now(), -TimeZoneOffset(), Minutes ),
Activity_Date.SelectedDate
)
}
)
Interestingly although I used the Patch function to add a new record, I don't use the attendance_date_v variable in the Patch statement. Instead I use the following code:
Patch( '[dbo].[ActivityAttendance]',
Defaults( '[dbo].[ActivityAttendance]' ),
{ activitydate: Activity_Date.SelectedDate,
userpresent: Activity_User.Id,
capturedbyid: loggedin_user_v.id,
captureddate: Now(),
modifiedbyid: loggedin_user_v.id,
modifieddate: Now()
}
)
Collectively that code definely worked for the app I created at least...