Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to use UtcTimeFromLocalTime function in WebAPI?

Posted on by 116

Hi forum!

So we recently found ourselves in need of converting times from user's local time to UTC and other way around in Java script web resource.

To convert time to local time from UTC we used LocalTimeFromUtcTime function in WebAPI like following:


contoso.crm4.dynamics.com/api/data/v9.2/LocalTimeFromUtcTime(TimeZoneCode=@TimeZoneCode,UtcTime=@UtcTime)?@TimeZoneCode=47&@UtcTime=2021-05-05T00:00:00.000Z

and it worked perfectly fine.
But trying to do the opposite conversion we stuck with an issue. The request:
returns the error response:
{
    "error": {
        "code": "0x8006088a",
        "message": "Resource not found for the segment 'UtcTimeFromLocalTime'."
    }
}
Could you please help us with this, is UtcTimeFromLocalTime not supported yet in WebAPI, or we use it in not correct way?
  • Andy Kulyk Profile Picture
    Andy Kulyk 116 on at
    RE: How to use UtcTimeFromLocalTime function in WebAPI?

    Ah, I didn't notice that, now I get the format error too. So new challenge: what format does it want?

    But, yeah, the initial question is answered.

    Thank you!

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to use UtcTimeFromLocalTime function in WebAPI?

    Hello,

    Check the description of the function - docs.microsoft.com/.../utctimefromlocaltime - it's described as collection bound (don't ask me, I'm clueless).

    Here is what I was able to compose that bypassed the issue you experienced:

    /api/data/v9.2/resourcegroups/Microsoft.Dynamics.CRM.UtcTimeFromLocalTime(TimeZoneCode=@TimeZoneCode,LocalTime=@LocalTime)?@TimeZoneCode=47&@LocalTime=2021-05-05T00:00:00.000Z

    But my example has issues with datetime format.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans