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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Datetime field issue on dynamics 365

(0) ShareShare
ReportReport
Posted on by 75

Hi,

I am retrieving all accounts data using FetchXML on a console application. When I retrieve data the Date of birth(DateTime) field retrieve is getting -1 day. e.g. If a date of birth is 19/09/1990 then on console application it shows 18/09/1990. How can I solve this problem to get the perfect date?

Thanks in advance

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sreevalli Profile Picture
    3,264 on at

    Hi,

    It is because of the time difference in your computer time and the CRM timzone.

    Below code will return the time difference in minutes and then you can +/- to your local time.

    public int? RetrieveCurrentUsersTimeZoneSettings(IOrganizationService service)

    {

        var currentUserSettings = service.RetrieveMultiple(

        new QueryExpression("usersettings")

        {

           ColumnSet = new ColumnSet("localeid", "timezonecode"),

           Criteria = new FilterExpression

           {

               Conditions =

           {

               new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)

           }

           }

        }).Entities[0].ToEntity<Entity>();

        return (int?)currentUserSettings.Attributes["timezonecode"];

    }

  • Kiran_girase Profile Picture
    75 on at

    Thanks for reply Sreevalli,

    I am working on-premise CRM using VPN and sometimes date retrieve perfect and sometimes -1 of day.

  • Suggested answer
    Sreevalli Profile Picture
    3,264 on at

    Hi,

    Its depends on system time difference with current working computer.

    eg: if it is 8hr and the your CRM field is having 18/01/19 6:00:00 then it will be on same day as it will add 8hrs and the final time would be 14:00:00. but if your field contains 18/01/19 17hrs then after adding 8hrs it would be 19/01/19 01:00:00

  • Suggested answer
    ScottDurow Profile Picture
    23 on at

    Exactly - time zones are tricky when working with absolute dates. Microsoft have now implemented time zone independent date fields for this kind of date - see docs.microsoft.com/.../behavior-format-date-time-field

    Hope this helps

  • Verified answer
    Kiran_girase Profile Picture
    75 on at

    Thanks for answering,

    My issue has been solved by putting,

    DateTime dt = (DateTime)entity.Attribute["datefield"];
    DateTime dt1 = dt.AddHours(+5).AddMinutes(+30);

    Thanks

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans