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)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.