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 / PCF - Time-Zone Indepe...
Power Apps
Unanswered

PCF - Time-Zone Independent DateTime gets corrupted when bound to PCF control

(0) ShareShare
ReportReport
Posted on by 50

Hi,

 

I’m binding a PCF control to a field of type DateAndTime.DateAndTime which is defined in Dataverse as Time-Zone independent, i.e. everything is in UTC.

 

In order to rule out any date arithmetic inside the control, as a test I’ve built a control which simply copies one field to another (so you need 2 DateTime fields, both of which must be time-zone independent). When you run it, the fields end up with different values.

 

My ControlManifestInput.xml (with some boilerplate removed for brevity) looks like:

 

 

<property name="destinationDate" of-type="DateAndTime.DateAndTime" usage="bound" required="true" />
<property name="sourceDate" of-type="DateAndTime.DateAndTime" usage="input" required="true" />

 

 

And the guts of the class is:

 

 

private notifyOutputChanged: () => void;
private sourceDate: Date | null;

public init(…):{
 this.notifyOutputChanged = notifyOutputChanged
}

public updateView(…):{
 this.sourceDate = context.parameters.sourceDate.raw
 this.notifyOutputChanged()
}

public getOutputs(): {
 return { destinationDate: new Date(this.sourceDate!) }
}

 

 

Let’s say I set the source date to April 21 2023 9am UTC, the control is correctly called with a sourceDate value of 1682067600000. The control copies this to the destination date but PowerApps immediately calls updateView with destinationDate equal to 1682071200000 (which corresponds to 10am UTC on the same day). If you save the record from the screen these are the values that get persisted to the database.

 

Since the error is 1 hour and my current time zone (UK) is one hour away from UTC I tried setting my local time zone to Paris and sure enough the destinationDate instead gets set to 1682074800000 (which is 11am UTC on the same day – 2 hours from the input date).

 

So it seems that something in the PCF is trying to do some kind of time zone adjustment even though both dates are UTC, and even though JavaScript dates can’t hold Time Zone information.

 

Note this does not depend on the user’s PowerApps time zone setting or their Microsoft account time zone setting; just the local PC time zone setting (I have tried with both Firefox and Chrome on PC but not on other operating systems). I'm reluctant to put a workaround in my code because other environments might not have the same bug and then the control would produce the wrong result.

I have the same question (0)
  • satz76 Profile Picture
    2 on at

    I am facing the same issue, did you resolve this .?

  • Tim Robinson Profile Picture
    50 on at

    I never received any recognition that this is a bug, so I ended up putting in a workaround.

     

    For instance, if you want to set the output date to 15:07 UTC you have to actually return 15:07 Local time which is what this function does.

     

    const fudgeDateForPowerApps = (d: Date) =>
    new Date(
    d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(),
    d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()
    )

     so instead of calling:

    notifyOutputChanged({theDate: myDate})

    you call:

    notifyOutputChanged({theDate: fudgeDateForPowerApps (myDate)})


    Obviously if they fix the bug then your code will start generating incorrect results.

     

    It may be there's some other factors affecting the bug which I'm not aware of (for instance I've only tested with PowerApps hosted in the UK), but as far as I know this is currently working for me and customers all over the world 

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 547

#2
WarrenBelz Profile Picture

WarrenBelz 444 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 322

Last 30 days Overall leaderboard