Welcome back with another post on PowerApps. We all face DateTime issue when using PowerApps with Power Automate and SharePoint. The reason is that time zone of all these portal is different due to which when we send DateTime value from PowerApps to SharePoint, it gets changed according to the time zone.
The possible solution provided by PowerApps is to set Date time zone to Local as shown in screen below-
But it also not works well. See how-
I had created a list having 2 columns-
- Title - Single line of text
- WorkDate - DateTime (include time also)
Clearly, there is a difference in both datetime even I had set the Date time zone to Local.
Therefore, I came up with another workaround. Suppose we have to capture InDateTime. Let's see-
- Instead of creating a DateTime column, create 2 columns-
- "InDate" - Single line of text
- "InTime" - Single line of text
- Now in PowerApps, use Date picker as date column "dpInDateEdit". Set Date time zone to Local.
- Use drop down to create Hours (ddlInTimeHoursEdit) & Minutes (ddlInTimeMinutesEdit).
- This way you can create your own DateTime picker.
- Now the question is how to bind current value on screen load in New Entry Form and the default value in Edit Form. For this-
- New Form -
- Choose the DefaultDate property of "dpInDateNew" control and set it to -
Today()
- Choose the Default property of "ddlInTimeHoursNew" control and set it to -
If(Hour(Now()) < 10,Concatenate("0",Text(Hour(Now()))),Hour(Now()))
- Choose the Default property of "ddlInTimeMinutesNew" control and set it to -
If(Minute(Now()) < 10,Concatenate("0",Text(Minute(Now()))),Minute(Now()))
- Edit Form -
- Choose the DefaultDate property of "dpInDateEdit" control and set it to -
BrowseGalleryListItems.Selected.InDate
- Choose the Default property of "ddlInTimeHoursEdit" control and set it to -
First(Split(BrowseGalleryListItems.Selected.InTime,":")).Result
- Choose the Default property of "ddlInTimeMinutesEdit" control and set it to -
Last(Split(BrowseGalleryListItems.Selected.InTime,":")).Result
- You will be surprising that why I am splitting the time. The reason is that while saving the data from New/Edit form to SharePoint, I am concatenating the Hours & Minutes value to save in list.
UpdateContext({varInTime:Concatenate(ddlInTimeHoursEdit.SelectedText.Value,":",ddlInTimeMinutesEdit.SelectedText.Value)});
- Before saving the date, I am changing it to DatePicker format so that next time, when I will bind it to this control on Edit Form, it will create any issue-
UpdateContext({varInDate:Text(dpInDateEdit.SelectedDate,"mmmm d, yyyy")});
- This way, we can resolve the DateTime issue of timezone.
- In case, if you wish to save the complete datetime in one column, you may concatenate all 3 values as per the required format and save in single column.
- While fetching, you need to split the same and fetch the desired value from the array accordingly.
- That's all for this topic.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.