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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to change dateTime to current date when retrieved in Plugin

(0) ShareShare
ReportReport
Posted on by 410

Hi All,

    I dont know if someone can help me in this, because dynamic CRM uses a UTC time and it is always a day before current time, I created a plugin, but when it retreved and assign the retrieved to a new entity field, the creation date is always in a day before, rather than the current local time, it was rerieved and created. RaviKashyap, , Arun Vinoth Example:

new_clinic target = (new_clinic)context.InputParameters["Target"];
DateTime newClinicDate = (DateTime)target.new_ClinicDate;
foreach (Entity conRole in ec.Entities)
                    {
                        conRole.Attributes["new_date"] = newClinicDate;
                        conRole.Attributes["new_clinicdate"] = newClinicDate;
                        service.Update(conRole);

In the above example, the updated has a an old date, rather than the date in the parent entity. Hw do i make the be current ??


]

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    I am not sure if you are aware of this but you can change this behavior i.e. instead of storing it as UTC, storing it is timezone independent or date only. Refer the below articles-

    docs.microsoft.com/.../behavior-format-date-time-field

    technet.microsoft.com/.../dn946904.aspx

    community.dynamics.com/.../205797

    So if it is not important for you to show timezone then you can change the behavior to date so that it will be saved, retrieved, displayed as date only ( no utc conversion).

    If you want to keep the date as is i.e UTC then you need to do the conversion. In my scenarios, most of my client are on AEST so I have hardcoded +10 hrs. The other option is to use the message to convert the timezone. msdn.microsoft.com/.../microsoft.crm.sdk.messages.localtimefromutctimerequest.aspx

    Hope this helps.

  • Victor Onyebuchi Profile Picture
    410 on at

    Thanks Ravi!! you have always come to my rescue

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    If it helped you, please mark the suggestion as helpful and close the thread.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Victor,

    Your code is correct ,this  is expected behavior . If you don't want UTC format you can change the date format and behavior by going to field properties. You can follow above article shared by Ravi and also to better understanding with scenario you can have a look  Scott's blog.

    community.dynamics.com/.../dynamics-crm-datetimes-the-last-word

  • Victor Onyebuchi Profile Picture
    410 on at

    Thanks @Goutam, that link was useful.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans