web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

custom workflow - own date functions arent working correct (timezone problem (german tz +2))

(0) ShareShare
ReportReport
Posted on by

Hi,

we created some custom workflows to handle date f.e. date offset, create date, date extract etc.

the result is not as expected. It is +2 hours.

What we did:

protected override void Execute(CodeActivityContext context)
        {
            int year = Year.Get<int>(context);

            int month = Month.Get<int>(context);

            int day = Day.Get<int>(context);

            int hour = Hour.Get<int>(context);

            int minute = Minute.Get<int>(context);

            int second = Second.Get<int>(context);

            Result.Set(context, new DateTime(year, month, day, hour, minute, second).ToUniversalTime());
        }

protected override void Execute(CodeActivityContext context)
        {
            int year = Year.Get<int>(context);

            int month = Month.Get<int>(context);

            int day = Day.Get<int>(context);

            int hour = Hour.Get<int>(context);

            int minute = Minute.Get<int>(context);

            int second = Second.Get<int>(context);

            Result.Set(context, new DateTime(year, month, day, hour, minute, second).ToUniversalTime());
        }

Date: 1. June 2018 00:00:00
if we do a new DateTime(18, 6, 1, 0, 0, 0).ToUniversalTime());

we expect to get: 31.5.18 22:00:00 cause we did ToUniversalTime() because we thougt to get the correct results if we only use utc times in all custom workflows steps with date functions.

then we store it in the date attribute (the 31.5.18 22:00) and expect that it is showed as 1.6.18 00:00.

But it is showed as 1.6.18 02:00

Why?

and if we use the TimeZoneInfo.ConvertTimeToUtc(.... or if we use the convert to CET .. it returns the same result. We expected to get a difference from 2 hours if one is converted to utc and the other is converted to cet.

Please can you help?

many thx, Peter

*This post is locked for comments

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at
    RE: custom workflow - own date functions arent working correct (timezone problem (german tz +2))

    I think the issue stems from the fact that functions like .ToUniversalTime are .Net functions, and will use the Windows timezone of the Windows account under which the code is running, and do not use the CRM timezone settings.

    If you have CRM OnPremise, you can change the Windows timezone of the account(s). If you're in CRM Online then you have no control over this; instead you could get the timezone offset from the CRM usersettings, and apply that adjustment.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans