what is difference between using DateTimeUtil::getSystemDateTime(); and DateTimeUtil::utcNow();
Can anyone please explain?
Thank You.
*This post is locked for comments
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.
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
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.
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.
Thanks Martin!
I have changed it to use UTC now. Should I also use DateTimeUtil::removeTimeZoneOffset() ?
No, utcNow() already returns UTC. You can easily test it if you're not sure.
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.
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.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Community Member 4
Martin Tocauer 4
Nayyar Siddiqi 2