Unix Datetime UTC

Here’s a little trick to generate a Unix Datetime in UTC.

 PROCEDURE DT2UnixDTUTC@81237(DtIn@81200 : DateTime) : BigInteger;
 VAR
   DtOffset@81203 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.DateTimeOffset";
   DtUtc@81206 : DateTime;
   Duration@81208 : Duration;
   TempDate@81209 : Date;
   TempTime@81210 : Time;
 BEGIN
   EVALUATE(TempDate, COPYSTR(FORMAT(DtIn, 0, 9), 1, 10));
   EVALUATE(TempTime, COPYSTR(FORMAT(DtIn, 0, 9), 12, 8));
   DtUtc := CREATEDATETIME(TempDate, TempTime);
   Duration := DtIn - DtUtc;
   DtOffset := DtOffset.DateTimeOffset(DtIn);
   EXIT(DtOffset.ToUnixTimeMilliseconds + Duration);
 END;
No comments yet.

Leave a Reply