Hi Everyone, I have an update plugin on Date and Time and I have to perform some operation from it.
As I am getting the DateTime field from Images, I am getting Wrong Time in it.
Can Anyone tell me how to get the appropriate time.
DateTime StartTime = PostImage.Contains("ccs_dailer_startdate") ? (DateTime)PostImage.GetAttributeValue<DateTime>("ccs_dailer_startdate") : DateTime.MinValue;
As you can see in the screenshot we got the wrong time.
Output:
StartTime: 02/23/2019 11:00
*This post is locked for comments
Hello,
As Kokulan suggested, .ToLocalTime() function will give you the correct time value.
Hope this helps!!
Charles Abi Khirs.
Hi
As suggested by Radu, the time displayed and retrieved in the plugin are different.
Time you see in the UI is the based on users time zone setting
Time you see in you get in the plugin using the following line is in UTC
DateTime StartTime = PostImage.Contains("ccs_dailer_startdate") ? (DateTime)PostImage.GetAttributeValue<DateTime>("ccs_dailer_startdate") : DateTime.MinValue;
To get the correct time in plugin based on users timezone, please use the following
DateTime StartTime = PostImage.Contains("ccs_dailer_startdate") ? (DateTime)PostImage.GetAttributeValue<DateTime>("ccs_dailer_startdate").ToLocalTime(): DateTime.MinValue;
https://stackoverflow.com/questions/179940/convert-utc-gmt-time-to-local-time
If I am doing any calculation in the plugin or Workflow, I normally convert to ToLocalTime so that I don't have an issue of losing an hour or adding an extra hour.
Hope this helps
Hello,
If the user under which the plug-in is executed and the one viewing the information on the form are different, then it could be to the TimeZone Conversion mechanism that is in place for CRM. If the field is defined as User Local: The field values are displayed in the user’s local time and formatted as per their current portal language/locale. The values are stored in UTC time zone format in Dynamics 365 for Customer Engagement. When a user in Dynamics 365 for Customer Engagement (or another portal user) in a different time zone views that value, they see it converted to their own time zone.
Please see: docs.microsoft.com/.../behavior-format-date-time-field
This means that if the user running the plugin and the one seeing the data in the UI are on different timezone, then this could explain the behavior
Basically a time offset is added between the date displayed in the plugin and the one shown in the UI.
I'd try changing in the personal options the timezone and see if this makes any difference - if not, then you'd need to calculate the time offset. Normally CRM does it for you.
Regards,
Radu
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6