Working with utcDateTime Functionality in Dynamics AX 2012

by | Updated August 15, 2016 | Development, Dynamics AX

Dynamics AX 2012 utilizes the utcDateTime data type to store date time information in the database using the Greenwich Mean Time definition of time. This allows the data to be date stamped in a manner that does not reflect the client or AOS time zone (this date/time stamp is considered to be time zone agnostic).

However, this means that some care may be needed in X++ code to correctly work with these values so the information can be displayed properly in some instances.

The Dynamics AX 2012 kernel has a nice class built in to allow us the ability to easily work with these values. The following job will demonstrate how to use just a few of the built in methods from this class:

The job is going to work with the Eastern, Central, and Pacific timezones within the United States.

After the variable declarations, the first method used is the DateTimeUtil::getSystemDateTime() method. This returns the current system dateTime as a type of utcDateTime, and there is NO timezone offset applied to the data.

The next line in the code simply shows the time displayed in an infolog. The use of the datetime2str built in function is shown as well to convert the utcDateTime type into a string for the infolog to use.

The next set of code is used to retrieve the current system datetime value, and apply the central timezone offset to the retrieved value:

This forces the date to be converted into Central Time zone.

NOTE: If it is desired to be converted based on where the user currently resides, the following code could be substituted:

The next set of code shows how we apply the timezone offset for the Eastern timezone.

This is as expected. Here is where it gets interesting however. What if it is desired to convert the above New York time to the Microsoft headquarters timezone in Redmond Washington? One would think that the following code would work:

However, this is incorrect. This code will apply the timezone offset as though the NYDateTime value is considered to be in GMT, which is it not. The correct code would be to take the NYDateTime value, strip off the timezone offset, and then apply the new timezone value to the GMT timezone. The code to do that is the following:

At this point, the offset value is applied correctly, and the desired information is retrieved.

Here is the output of the above job being run:

Info        Message (11:05:12 am) Current system datetime in GMT: 10/6/2014 04:05:12 pm

Info        Message (11:05:12 am) Current system datetime in my timezone: 10/6/2014 11:05:12 am

Info        Message (11:05:12 am) Current system datetime in NY timezone: 10/6/2014 12:05:12 pm

Info        Message (11:05:12 am) NY datetime in MS timezone (incorrect): 10/6/2014 05:05:12 am

Info        Message (11:05:12 am) NY datetime in MS timezone: 10/6/2014 09:05:12 am

For more information on the DateTimeUtil class, please see the following:

http://msdn.microsoft.com/en-us/library/datetimeutil.aspx

You can also view my post on working with utcDateTime fields in select statements.

 

Related Posts

0 Comments

Trackbacks/Pingbacks

  1. Working with utcDateTime Fields in Select Statements in Dynamics AX 2012 | Stoneridge Software Inc - […] See my previous post for more on working with utcDateTime functionality. […]

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

september

02sep10:00 am10:30 amThe Modern Manufacturer - Cycle Count Management

02sep12:00 pm12:30 pmBest Practices for Work Order Planning and Routing for Field Service Companies

09sep10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

09sep12:00 pm12:30 pmOverview of Microsoft Promotion for NAV and GP Clients

10sep11:00 am12:00 pmConfab with Stoneridge - Livestream - Field Service Comparisons

16sep10:00 am10:30 amThe Modern Manufacturer - Product Lifecycle Management

16sep12:00 pm12:30 pmHow to Upgrade to Dynamics 365 Finance and Operations: Examining Custom Code and ISV Implications

16sep2:00 pm2:30 pmScheduling and Dispatching for the Modern Field Service Company

23sep12:00 pm1:00 pmDynamics 365 Business Central Wave 2 Release Preview - An Overview of the Most Exciting New Features Coming in October

24sep11:00 am12:00 pmConfab with Stoneridge - Livestream - The Modern Workplace: Teams, Sharepoint, Outlook, Office, and AI Integration

30sep10:00 am10:30 amThe Modern Manufacturer - Return Management

30sep12:00 pm12:30 pmEmpowering Your Field Service Technicians with a Mobile Solution

october

07oct12:00 pm1:00 pmThe Three Paths to Business Central from Dynamics GP

08oct11:00 am12:00 pmConfab with Stoneridge - Livestream - The Vision and Strategy of Microsoft Business Systems

14oct10:00 am10:30 amThe Modern Manufacturer - Complex Cost Modeling

14oct12:00 pm12:30 pmGenerating Custom Inspection or Process Forms

19octAll Day22Stoneridge Connect Fall 2020

22oct11:00 am12:00 pmConfab with Stoneridge - Livestream - Stoneridge Connect Recap

28oct10:00 am10:30 amThe Modern Manufacturer - Engineering Change Orders

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X