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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Difference between using DateTimeUtil::getSystemDateTime(); and DateTimeUtil::utcNow();

(0) ShareShare
ReportReport
Posted on by 1,128

what is difference between using DateTimeUtil::getSystemDateTime();  and DateTimeUtil::utcNow();

Can anyone please explain?

Thank You.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi Ann,

    The utcNow method takes the current PC date/time.

    In AX you can change a session date/time to default these values e.g. when you want to enter a lot of transactions on a certain date. the getSystemDateTime returns this session specific date/time.

  • Ann2015 Profile Picture
    1,128 on at

    Hi Andre,  thanks for reply but the getSystemDateTime didn't work for us.

    We have a batch program that runs every morning at 2 am. We want to update a date field in ProjTable with today's date but for some weird reason it updates it to yesterdays date. I am using  getSystemDateTime . I am not sure what is going on.

    Thanks

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi Ann,

    It would be useful if you explained your issue in the initial question.

    The session date might be different due to e.g. timezone differences. Anyway, if you always needs the current date, you should use the utcNow method.

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    If you have a local time, you can't store it directly in database, because values there are expected to be in UTC. You have to use DateTimeUtil::removeTimeZoneOffset() to convert local time to UTC. For example, current UTC is Thursday, 19:11, but people in Sydney already have Friday, 05:11.

    I guess that's the problem.

  • Ann2015 Profile Picture
    1,128 on at

    Thanks Martin!

    I have changed it to use UTC now. Should I also use DateTimeUtil::removeTimeZoneOffset() ?

    Thank You.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    No, utcNow() already returns UTC. You can easily test it if you're not sure.

  • Ann2015 Profile Picture
    1,128 on at

    I have tested it but during the day it works fine. seems like when the program runs at 1 am (USA time)  it is getting messed up so I am concerned. I will check tomorrow and find out.

    Thanks for all your help.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I meant testing utcNow() in isolation, not testing it buried somewhere is a complex solution. That wouldn't tell

    you much, because if you get an unexpected result, you can't be sure which component is responsible. Do integration tests only after you test units.

    By the way, if you're doing black-box testing of such things, it's wise to set system timezone far away from UTC. If you have a small difference, such as just one hour, it's easy to overlook problems.

  • Mea_ Profile Picture
    60,284 on at

    Hi Ann2015,

    You can read this blog post to get more details about working with time and date in AX kashperuk.blogspot.co.nz/.../q-session-working-with-utcdatetime-from.html

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans