Today, we had an issue that a web service returned a timestamp in unixtime format, ie. all seconds that have passed since January 1st 1970.

We would like to convert that timestamp to a DateTime variable in AL Code.

We finally came up with these functions: UnixTimeToDateTime (see and DateTimeToUnixTime (see

See also the example calls at

procedure TestUnixTime();
	myCodeUnit: Codeunit myLibrary;
	nowUnixTime: BigInteger;
	FormatString: Text;
	nowDateTime: DateTime;
	nowUnixTime := myCodeUnit.DateTimeToUnixTime(CurrentDateTime);
	Message('to unixtime: ' + Format(nowUnixTime));
	nowDateTime := myCodeUnit.UnixTimeToDateTime(nowUnixTime);
	// formatting the date time to string
	FormatString := '<Day,2>.<Month,2>.<Year4> <Hours24,2>:<Minutes,2>:<Seconds,2>.<Thousands,3>';
	Message('from unixtime: ' + Format(nowDateTime, 0, FormatString));

Also note how you can specify the formatting of a date with the keywords Day, Month, Year4, Hours24, Minutes.

AL Coding: Converting DateTime and UnixTime timestamps in Dynamics NAV 2018
Tagged on: