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, ...
Suggested answer

Understanding DateTimeUtil::newdatetime

(0) ShareShare
ReportReport
Posted on by 897

Hi guys,

I'm trying to understand DateTimeUtil especially with method NewDateTime.When I have a field TransDate and entered as '28/10/2021", by using this code :

utcdatetime myDatetime;

myDatetime = DateTimeUtil::newdatetime(TransDate, 0);

Shouldn't this means I do not want the time detail ? In fact TransDate is Date type without time. But strange is why after this code ran, the utc field became "27/10/2021 05:00:PM" ?

My environment when I enter this is :

VM's set as UTC (Coordinated Universal Time), and at time enter is 1 PM, and my User Option - Preferences is set GMT - 8. 

I can understand if my VM's time is 1 AM, so calculate back 8 hours will be the previous day 5 PM, but my VM says 1 PM.

But the important is want to the same date, even when the field is with UTCDatetime. 

Thanks,

I have the same question (0)
  • Tony zhong Profile Picture
    897 on at
    RE: Understanding DateTimeUtil::newdatetime

    Hi both,

    Thanks,

    Yes, I think it is fine. If checked in SQL, it is correct as 00:00, and why it is displayed as 5PM I guess because even though the Timezone is set to GMT-8, but region is US which (my guess) last week still daylight saving, right? so move back 7 hours from 28/10/2021 00:00 ? I didn't check again now, but to me is ok, it is matter of display only, based on computer's region.

    And I'm using Transdate but have to get the utc format as I will use it for Dual-Write, the Dataverse counter part is datetime. And at first make me scared when I look at the date become previous date of the Transdate value it self.

    Issue solved.

    Thanks.

  • Suggested answer
    Leo Chen Profile Picture
    on at
    RE: Understanding DateTimeUtil::newdatetime

    Per my test, the method always return UTC time. 0 stands for start of a day so it implies 12:00 am. Doc as below -

    docs.microsoft.com/.../dynamics.ax.application.datetimeutil.newdatetime

    And the result has nothing do with your user preferred timezone setup in user option if your code resembles below. The outcome remains same before & after I changed my user time zone setup. 

    pastedimage1636504886224v1.png

  • André Arnaud de Calavon Profile Picture
    297,231 Super User 2025 Season 2 on at
    RE: Understanding DateTimeUtil::newdatetime

    Hi Tony,

    The method NewDateTime has a third parameter to remove the time zone offset.

    If you need a TransDate, why are you using this method?

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 665 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 595 Most Valuable Professional

#3
Yng Lih Profile Picture

Yng Lih 558

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans