Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Datetime field issue on dynamics 365

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

  • Verified answer
    Kiran_girase Profile Picture
    Kiran_girase 75 on at
    RE: Datetime field issue on dynamics 365

    Thanks for answering,

    My issue has been solved by putting,

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

    Thanks

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: Datetime field issue on dynamics 365

    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

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Datetime field issue on dynamics 365

    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

  • Kiran_girase Profile Picture
    Kiran_girase 75 on at
    RE: Datetime field issue on dynamics 365

    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
    Sreevalli 3,256 on at
    RE: Datetime field issue on dynamics 365

    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"];

    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans