Dynamics AX: utcDateTime Subtract Minutes and Hours

Hi, You can use this methods subtract datetime minutes or hours.

Subtract Minutes

public static utcDateTime subtractMinutes(utcDateTime _dt, int _value)
{
    utcDateTime     ret;
    System.DateTime sysDt   = _dt;
    System.TimeSpan sysTs   = new System.TimeSpan(0, _value, 0);
    ;

    ret = sysDt.Subtract(sysTs);
    return ret;
}

 

Subtract Hours

public static utcDateTime subtractHours(utcDateTime _dt, int _value)
{
    utcDateTime     ret;
    System.DateTime sysDt   = _dt;
    System.TimeSpan sysTs   = new System.TimeSpan(_value, 0, 0);
    ;

    ret = sysDt.Subtract(sysTs);
    return ret;
}

 

Usage

static void GuvenDateTimeSubtract(Args _args)
{
    utcDateTime dt = DateTimeUtil::getSystemDateTime();
    
    info(strFmt("From: %1, To: %2", dt, AYXDateTimeUtil::subtractHours(dt, 2)));
    info(strFmt("From: %1, To: %2", dt, AYXDateTimeUtil::subtractMinutes(dt, 2)));
}

Result

Leave a Reply

Your email address will not be published. Required fields are marked *