Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

How to convert epoch to utcdatetime in D365FO using X++

Bharani Preetham Peraka Profile Picture Bharani Preetham Pe... 3,634 Moderator
While working with integrations with some 3rd party application to FO, we might have scenarios where we get the current timestamp in Epoch/Unix Format. And we may need to flow that value to FO as a date time or just date. In that case, to use that in FO, we need to do some conversion.

We have a simple logic which we can use for this conversion.

Let's say we are getting the epoch value as a string in our payload. Then we can convert first that into real and pass the value into below method and then this method returns the final output in utcdatetime format.

//The field on LHS is a utcDateTime field.

this.PaymentDateTimeConverted = InvoiceUtility::convertUnixOrEpochTimeStampToDateTime(any2Real(this.PaymDateTime));


public static utcdatetime convertUnixTimeStampToDateTime(real _seconds)
{
    System.DateTime dtDateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind::Utc);
        
    dtDateTime = dtDateTime.AddSeconds(_seconds);

    // The below method converts DateTime to UtcDateTime
    return clrSystemDateTime2UtcDateTime(dtDateTime);
}

If we make this as above, we can call this method wherever required.



Happy Learning :)

Comments