I am trying to convert a datetime field value which comes in UTC to the time zone that a user can select in the "Time Zone" format field in dataverse using JS web resource but unable to do so. Not able to find the correct approach.
Here’s a general approach using JS Web Resource:
1.Get the user’s selected Time Zone Code (integer)
Assume this is stored in a field like new_timezone.
var timeZoneCode = formContext.getAttribute("new_timezone").getValue(); // TimeZoneCode (int)
Get the UTC datetime - var utcDate = formContext.getAttribute("new_utc_datetime").getValue();
Call LocalTimeFromUtcTime function = Dataverse exposes a function that you can call using Xrm.WebApi.online.execute:
function convertUtcToLocal(utcDate, timeZoneCode) {
var request = {
UtcTime: utcDate,
TimeZoneCode: timeZoneCode,
getMetadata: function () {
return {
boundParameter: null,
parameterTypes: {
UtcTime: {
typeName: "Edm.DateTimeOffset",
structuralProperty: 1
},
TimeZoneCode: {
typeName: "Edm.Int32",
structuralProperty: 1
}
},
operationType: 0,
operationName: "LocalTimeFromUtcTime"
};
}
};
Notes:
I have the same issue, if I choose the column to be time zone dependent then Dataverse will just display the time in a grid view completely wrong (off by a certain amout of hours as it trying to display UTC), so I have to use time zone independent.
Then if I want a feature like "due in days", which is = 'Due Date' - UTCtoday(), in power fx it will simply say cannot calculate time zone dependent value with time zone independent value.
This is a very common issues that's being troubling many users, so far I don't understand why Microsoft don't implement a fix instead they annouced that this is a "feature" update in the 2023 release wave 2 to support time zone calculation in power fx
Hi @RiyaKaul ,
Do you have a copy of the code you are trying to utilize? When you say "convert a datetime field value which comes in UTC" how it is coming in? Through an import, through the UI? Overall this makes a difference on what will happen within the application and dataverse.
Dataverse will always store the value in UTC so if you take the value you receive and store into a Time Zone Independent field it should store this as the time passed in. Check out this video with the multiple options and behaviors around datatime fields in Canvas Apps / Model Apps and Dataverse.
stampcoin
15
ankit_singhal
11
Super User 2025 Season 1
mmbr1606
9
Super User 2025 Season 1