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)

Wrong to date while fetch xml

(0) ShareShare
ReportReport
Posted on by

Hello Guys,

I am trying do a fetchxml where my from-date is 2016-09-06 and to-date is 2016-09-06 there are few records which are created on this date but when i do a fetch XML its displays me wrong Error Date

05-09-2016 06:30:00 PM

But the record was created today i.e 06-09-2016 i dunno why is displaying 05-09-2016 yesterdays date i am using date time field and behavior is local please help 

<fetch mapping="logical" version="1.0" >
<entity name="hd_error" >
<attribute name="hd_errorsource" alias="ErrorSource" />
<attribute name="hd_errmessege" alias="ErrorMessage" />
<attribute name="hd_errorevttyp" alias="ErrorType" />
<attribute name="hd_errorlogdat" alias="ErrorDate" />
<order attribute="hd_errorlogdat" />
<filter>
<condition attribute="hd_errorlogdat" operator="on-or-after" value="2016-09-06" />
<condition attribute="hd_errorlogdat" operator="on-or-before" value="2016-09-06" />
</filter>
</entity>
</fetch>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe that this is because your datetime field is stored in UTC format. Here is explanation - www.powerobjects.com/.../crm-2011-truths-about-datetime

    Could you please answer where do you use that fetchxml and get this result?

  • Community Member Profile Picture
    on at

    Its a wcf service were i am using fetchxml

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Got it. Can you please provide code that gives you client of endpoint and code that you use to retrieve data from CRM?

  • Community Member Profile Picture
    on at

    My local machine (UTC+05:30) Chennai,Kolkata,Mumbai,New Delhi

  • Community Member Profile Picture
    on at

    Try

               organizationUri = New Uri(ConfigurationManager.AppSettings("url"))

               credentials.UserName.UserName = ConfigurationManager.AppSettings("username")

               credentials.UserName.Password = ConfigurationManager.AppSettings("password")

               Using _serviceProxy = New OrganizationServiceProxy(organizationUri, Nothing, credentials, Nothing)

                   _service = DirectCast(_serviceProxy, IOrganizationService)

                   'Prepare SQL

                   Dim errorlog As String = "<fetch mapping='logical' version='1.0'>" +

                                                  " <entity name='hd_error'>" +

                                                      " <attribute name='hd_errorsource' alias='ErrorSource'/>" +

                                                      " <attribute name='hd_errmessege' alias='ErrorMessage'/>" +

                                                       "<attribute name='hd_errorevttyp' alias='ErrorType'/>" +

                                                       "<attribute name='hd_errorlogdat' alias='ErrorDate'/>" +

                                                       "<order attribute='hd_errorlogdat'/>"

                   If Len(value1) > 0 And Len(value2) > 0 Then

                       errorlog = errorlog & "<filter>" +

                                            " <condition attribute='hd_errorlogdat'operator='on-or-after' value='2016-09-06'  />" +

                                               "<condition attribute='hd_errorlogdat'  operator='on-or-before' value='2016-09-06' />" +

                                               "</filter>"

                   End If

                   errorlog = errorlog & "</entity>" +

                                                    " </fetch>"

                   Dim queryResult = _service.RetrieveMultiple(New FetchExpression(errorlog))

                   Try

                       dt.Columns.Add("SlNo", GetType(System.String))

                       dt.Columns.Add("ErrorSource", GetType(System.String))

                       dt.Columns.Add("ErrorMessage", GetType(System.String))

                       dt.Columns.Add("ErrorType", GetType(System.String))

                       dt.Columns.Add("ErrorDate", GetType(System.String))

                       ' Populate the DataTable

                       '

                       'Dim drDSRow As DataRow

                       Dim drNewRow As DataRow

                       For Each item In queryResult.Entities

                           Dim errsource As String = DirectCast(item("ErrorSource"), AliasedValue).Value.ToString()

                           Dim errmess As String = DirectCast(item("ErrorMessage"), AliasedValue).Value.ToString()

                           Dim errtyp As String = DirectCast(item("ErrorType"), AliasedValue).Value.ToString()

                           Dim errdate As String = DirectCast(item("ErrorDate"), AliasedValue).Value.ToString()

                           drNewRow = dt.NewRow()

                           drNewRow("SlNo") = ctr

                           drNewRow("ErrorSource") = errsource

                           drNewRow("ErrorMessage") = errmess

                           drNewRow("ErrorType") = errtyp

                           drNewRow("ErrorDate") = errdate

                           dt.Rows.Add(drNewRow)

                           ctr = ctr + 1

                       Next

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    One more question. Can you please check what's your TimeZone set in CRM Personal Settings?

  • Community Member Profile Picture
    on at

    (GMT+05:30)) Chennai,Kolkata,Mumbai,New Delhi

    Thank you

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Ok. Try to use ToLocalTime for datetime field to get correct result - msdn.microsoft.com/.../system.datetime.tolocaltime(v=vs.110).aspx

  • Community Member Profile Picture
    on at

    Thank you very much Andrii Butenko

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