I've seen quite a few postings about correctly handling datetime fields, but none of them seem to solve my problem.
I'm trying to write to the msdyn_date attribute of the msdyn_timeentry entity in Dynamics 365 (part of Project Serivce Automation). When I query the data that has been created via the regular UI through the web api, the dates are in a format like this:
"msdyn_date":"2018-12-12T06:00:00Z"
I assume that the datetime PowerApps needs to pass should be in this same form with the correct time zone offset. To do this the update property of the applicable data card is this:
Text(DateAdd(DataCardValue2.SelectedDate,TimeZoneOffset(Today()),Minutes),"[$-en-US]yyyy-mm-ddThh:mm:ssZ")
I duplicated the above in a label for testing purposes and it seems to yield the correct result. As an exmple, on 12/13/2018 in the Central Time Zone of the US, this value displayed in the label is: 2018-12-13T06:00:00Z.
However when I query the created record through the web api, the date in that record is 2018-12-13T00:00:00Z, i.e. the time zone got lost along the way.
What is the correct way I should be formatting the date field to post correctly? The app is a canvas app.
Solved! Go to Solution.
Hi @r529,
Does your Dynamics 365 environment have same Time Zone as your local time zone?
Could you please share a screenshot about your app's configuration?
When storing date time value in Dynamics 365, the date time value would be stored in UTC time zone format. But when you see it within your Dynamics 365, this value would be converted to your local time zone.
So on your side, if the Time Zone of your Dynamics 365 has been set to your local time zone, the 2018-12-13T06:00:00Z value would be stored as a UTC Time Zone format, when you see it within your D365, this value would be converted into your local time zone -- 2018-12-13T00:00:00Z.
As an alternative soltuion, you could consider modify the Text formula within your app as below:
Text(
DateAdd(DataCardValue2.SelectedDate,TimeZoneOffset(Today())*2,Minutes),
"[$-en-US]yyyy-mm-ddThh:mm:ssZ"
)
then check if the issue is solved on your side.
In addition, you could also consider take a try to add a Text type column within your D365 entity to store the Date Time value passed from your app instead of Date Time type column, after that, you don't need to care about the Time Zone issue, you could store the Date Time value into this Text Type column directly.
Best regards,
Kris
Hi @r529,
Does your Dynamics 365 environment have same Time Zone as your local time zone?
Could you please share a screenshot about your app's configuration?
When storing date time value in Dynamics 365, the date time value would be stored in UTC time zone format. But when you see it within your Dynamics 365, this value would be converted to your local time zone.
So on your side, if the Time Zone of your Dynamics 365 has been set to your local time zone, the 2018-12-13T06:00:00Z value would be stored as a UTC Time Zone format, when you see it within your D365, this value would be converted into your local time zone -- 2018-12-13T00:00:00Z.
As an alternative soltuion, you could consider modify the Text formula within your app as below:
Text(
DateAdd(DataCardValue2.SelectedDate,TimeZoneOffset(Today())*2,Minutes),
"[$-en-US]yyyy-mm-ddThh:mm:ssZ"
)
then check if the issue is solved on your side.
In addition, you could also consider take a try to add a Text type column within your D365 entity to store the Date Time value passed from your app instead of Date Time type column, after that, you don't need to care about the Time Zone issue, you could store the Date Time value into this Text Type column directly.
Best regards,
Kris
Thanks for your help.
For the time zone question, if you're referring to my user time zone setting, it is set to my local time zone. I was familiar with how D365 store datetime in UTC and how it coverts it at rendering in the UI. That is what made me suspect something was missing with the time zone offset portion. When I pulled the relevant record through the Web API, the time zone offset was missing for those records created through the Power App but not those created through the regular UI.
I've attached a screenshot. I will also try the first alternative your provided.
I'm hesitant to create a second date attribute in D365 as a workaround.
User | Count |
---|---|
139 | |
129 | |
75 | |
74 | |
69 |
User | Count |
---|---|
221 | |
135 | |
79 | |
58 | |
56 |