Search code examples
datetimecompareaxaptadynamics-ax-2012dynamics-ax-2012-r2

Multiple UTC date time comparison


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.


Solution

  • I succeeded my logic, by using this, thanks though.

    str                lastUser;
    utcDateTime        highest = DateTimeUtil::minValue();
    
    ttsBegin;
    while select ItemId, CreatedDate, User  from this
        where this.ItemId == _itemId // && this.ProductType == Options::Changed
        {
          //  info(strFmt("CurrentDate: %2", this.ItemId, this.CreatedDate));
        /*    if(this.CreatedDate < loweste)
            {
                loweste = this.CreatedDate;
            } */
             if(this.CreatedDate > highest)
            {
                highest = this.CreatedDate;
                lastUser = this.User;
            }
         //   info(strFmt("lowest is: %1" , loweste));
         //   info(strFmt("highest is: %1 ", highest));
       /*     if(loweste < highest)
            info(strFmt("highest is: %1" , loweste));
         */
        }