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 :
Microsoft Dynamics AX (Archived)

Logic problem - UTC dateTime comparison

(0) ShareShare
ReportReport
Posted on by 275

I have these records in my table:

11/11/2015 04:48:05 pm

11/11/2015 04:50:58 pm

11/11/2015 05:07:17 pm

11/11/2015 05:08:32 pm 

When i use my DateTimeUtil::getSystemDateTime(); - todays time

i need to compare the other records with todays time, to find the record which is closest to the current datetime.

I am thinking of using DateTimeUtil::getDifference but i can't make the logic right when there are more then two UTC dateTime.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Logic problem - UTC dateTime comparison

    You'll need two queries:

    • find highest time lower than or equal to the current time
    • find lowest time higher than or equal to the current time

    Then compare these two values and you're done.

  • Ashein Profile Picture
    275 on at
    RE: Logic problem - UTC dateTime comparison

    Even when i use DateTimeUtil::utcNow(), how can i get the the closest record that is to the current time ? when i use < or > i get all the records, not the lowest.

    And i will remember to not use # and seperate the tags

  • Suggested answer
    Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Logic problem - UTC dateTime comparison

    You don't need getDifference() or any unusual operator, operators such as < and > will do the job. The problem is that you're comparing apples and oranges: UTC values in database with the local time returned by DateTimeUtil::getDifference(). The easiest way is to get the current UTC time by calling DateTimeUtil::utcNow().

    By the way, please make sure that you separate tags by comma or semicolon and don't prefix them with # (this is no Twitter). You created a single tags with text #Datecomparison #UTCDateTime #, which wasn't very useful.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 2

#2
Rahul Shah Profile Picture

Rahul Shah 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans