Search code examples
axaptax++dynamics-ax-2012timezone-offset

Converting Date to CurrentCompany timeZone in Dynamics ax x++


I have a scenario where i need to convert a Datefield(joindate) to currentcompany timezone date. And then i need to compare this with anotherdate(startdate). If the difference is more than 365 days i need to give an warning. Can someone help me in this. Thanks in advance.


Solution

  • You can apply a timezone to an utcdatetime via DateTimeUtil::applyTimeZoneOffset
    The company timezone can be retrieved by calling DateTimeUtil::getCompanyTimeZone

    Afterwards calculate the difference by calling DateTimeUtil::getDifference, which returns the difference in seconds so you have to compare that with the seconds per year.
    To avoid inserting a 'magic' number, use the constants in the macro library TimeConstants.