Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Control UTC time in server side

(0) ShareShare
ReportReport
Posted on by 645

I saved a record in 17:16:15,  I run a job which gets the ModifiedOn field of my record which is 15:16:15, my GMT is +2, I want to know how to fix that gap that my result will turn out like it should be - 17:16:15. I can't select it from DB I beed a solution in server side (c# I mean)  what can U do in that case

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Control UTC time in server side

    Hi Sahara,

    I believe your instance server is in another country and hence you are getting value of that timezone.

    Please do refer following code for your reference that you can use to return your timezone code in c#.

    public int? RetrieveCurrentUsersSettings(IOrganizationService service)

           {

               QueryExpression queryExpression = new QueryExpression("usersettings")

               {

                   ColumnSet = new ColumnSet(new string[] { "timezonecode" })

               };

               FilterExpression filterExpression = new FilterExpression();

               filterExpression.Conditions.Add(new ConditionExpression("systemuserid", ConditionOperator.EqualUserId));

               queryExpression.Criteria = filterExpression;

               Entity currentUserSettings = service.RetrieveMultiple(queryExpression).Entities[0].ToEntity<Entity>();

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

           }

           public DateTime RetrieveLocalTimeFromUTCTime(DateTime utcTime, int? timeZoneCode, IOrganizationService service)

           {

               DateTime localTime;

               if (timeZoneCode.HasValue)

               {

                   LocalTimeFromUtcTimeRequest localTimeFromUtcTimeRequest = new LocalTimeFromUtcTimeRequest()

                   {

                       TimeZoneCode = timeZoneCode.Value,

                       UtcTime = utcTime.ToUniversalTime()

                   };

                   localTime = ((LocalTimeFromUtcTimeResponse)service.Execute(localTimeFromUtcTimeRequest)).LocalTime;

               }

               else

               {

                   localTime = DateTime.Now;

               }

               return localTime;

           }

    ttidbit.blogspot.com/.../crm-timezone-codes.html

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Control UTC time in server side

    Hi ,

    Please refer below article -

    [View:http://patelprathmesh.blogspot.com/2015/03/get-local-datetime-from-utc-datetime-in.html?m=1]

    You can also use DateTime.ToLocalTime() , it will return server local time where the code will execute.

    [View:https://stackoverflow.com/questions/12937968/converting-utc-datetime-to-local-datetime/12938028]

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans