Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

DateTimeUtil::utcNow returning date from another timezone.

Posted on by 2,983

DateTimeUtil::utcNow. According to the MSDN: "This method is run on the server, so that the time that is returned is the system time of the server"

However, If I create a method with this code:

private void TimeTest()
{
    str MyDate;
    ;
    MyDate= DateTimeUtil::toStr(DateTimeUtil::utcNow());
    Box::info(MyDate);
}


It returns the time from another TImezone. I've checked my user's timezone in AX and also the AOS Server timezone, and both have London timezone. When server time is 11:00, it returns 10:00

utc.png

Any ideas on what can be causing this behaviour?

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DateTimeUtil::utcNow returning date from another timezone.

    Like Martin suggests, you're looking at the wrong method call:

    here are some options for you to use:

    today();                              // print system date on AOS where the code is executed

    systemDateGet();               // print the AX session date.

    To see the difference, you will need to change the session date of AX (Tools --> Session date on the client)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: DateTimeUtil::utcNow returning date from another timezone.

    As the name suggests, utcNow() returns in time in UTC (Coordinated Universal Time), not in any local timezone. What the documentation talks about is what's the source; it doesn't mean that utcNow() doesn't return UTC.

    You can apply a time zone by DateTimeUtil::applyTimeZoneOffset(), if you want a local time instead of UTC.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans