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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Date different of original xml field

(0) ShareShare
ReportReport
Posted on by 183

I have created a custom integration with another system to create invoice journals in Dynamics 365 Finance. In development environments (tested in 2 DEVs environments) the invoice date is correct, but in UAT environments the invoice date is less one day.

DEV environment in LCS (right date)

pastedimage1591020849054v2.png

UAT environment in LCS (wrong date)

pastedimage1591020490451v1.png

I'm using the code (DateTimeUtil::date(invoiceDate) to get the date.

Anyone know what is wrong?

I have the same question (0)
  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: Date different of original xml field

    Is is a date field or an utcDateTime field? Is the input in UTC or another time zone? Do you have the same preferred time zone in both environments? I see that they have different date formats; maybe they differ in time zone as well.

    The only code you've showed us is the call of DateTimeUtil::date() and it's safe to assume that this standard method works correctly. Therefore the problem is either in how you populate invoiceDate or how you use the value returned by DateTimeUtil::date(). But we know nothing about either part of your code - you will have to give us more information.

  • Rafael Araujo Profile Picture
    183 on at
    RE: Date different of original xml field

    Hi Martin,

    It is an utcDateTime and I didn't set the timezone in the code. The timezone in Legal Entity and in user option is the same in both environment (London time zone). The part of code that get the date is below.

    // get  xml element
    xmlTagInvoiceDate = xmlTagInvoice.getNamedElement(#XmlTagInvoiceDate);
    if (xmlTagInvoiceDate)
    {
    	invoiceDate = System.DateTime::Parse(xmlTagInvoiceDate.text());
    }

  • WillWU Profile Picture
    22,361 on at
    RE: Date different of original xml field

    Hi Rafael,

    DateTime value is stored in database in UTC.

    You could try to get the date field from the database to check if there is any problems.

    Please try to use DateTimeUtil::applyTimeZoneOffset method to set the user time zone offset.

    https://docs.microsoft.com/en-us/dynamicsax-2012/developer/convert-from-time-zone-before-persisting-in-x

  • Verified answer
    Rafael Araujo Profile Picture
    183 on at
    RE: Date different of original xml field

    Hi Will WU and Martin Dráb,

    I solved the issue using the code below:

    // get  xml element
    xmlTagInvoiceDate = xmlTagInvoice.getNamedElement(#XmlTagInvoiceDate);
    if (xmlTagInvoiceDate)
    {
        invoiceDate = DateTimeUtil::applyTimeZoneOffset(
            System.DateTime::Parse(xmlTagInvoiceDate.text()), 
            DateTimeUtil::getUserPreferredTimeZone());
    }

    Thanks!!!

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: Date different of original xml field

    Are you sure it's correct? applyTimeZoneOffset() is used to convert a UTC value to a local time zone. But you want the opposite, don't you? You have a local time with an offset (e.g. UTC+1) and you want to remove this offset to get an UTC value. Therefore you should use removeTimeZoneOffset() instead of applyTimeZoneOffset().

  • Rafael Araujo Profile Picture
    183 on at
    RE: Date different of original xml field

    Hi Martin,

    We will use the user (that will setup the batch job) time zone.

    Thanks :)

  • Abigail Profile Picture
    552 on at
    RE: Date different of original xml field

    Have you set similar time zones in the different environment?

    The code you used is how standard and there is nothing wrong with it.

    Set the right timezones and then try the code.

  • Rafael Araujo Profile Picture
    183 on at
    RE: Date different of original xml field

    Hi Abigail,

    No, is the same time zones in all environments. I did the database copy from production to QA and DEV environment, but only in DEV environment was working. I needed to change the code to apply the time zone correctly.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,850

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 795 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 519 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans