Get current UTC time in AL

idonavidonav Posts: 31Member
Hi all,

I would like to find a way to get the current UTC date in AL. I've been messing around with DateTime and similar, but it seems like it takes the user agent time zone in to account (which is out of our control), and it all just becomes a big mess with DateTimes not making any sense.

So, I need a way to get current UTC time, it is not an option to do a get request to external services, neither tampering with client computer time zones (spread around the world). All servers have their timezone set to UTC, so maybe I could fetch it from there in some way?

Suggestions appreciated, seems like a super simple task, but for some reason I'm not getting it to work.

Best Answer


  • KTA8KTA8 Posts: 301Member
    You can use a default .net object that get that system data (you don't have to develop it) and put that in run on client = false; that should work
  • idonavidonav Posts: 31Member
    DateTime.UtcNow from mscorlib would probably work if I developed a C/AL solution, but I need to do it in AL.
  • ftorneroftornero Posts: 274Member
    In BC on-premise you can interop whit dotNET from AL, I don't know if that is your case.

    This is the link:
  • idonavidonav Posts: 31Member
    edited 2019-02-15
    Thank you @ftornero, that works perfectly fine. The problem described in the initial post only occurs when saving it to a datetime variable, but saving it as a string does the job.

    Full code below, for other (not related to this) reasons, I had to convert it to a BigInt:
        procedure GetCurrentUtcTime() UtcTime: BigInteger;
            DateTime: DateTime;
            TempTime: Text;
            DateTime := CurrentDateTime();
            TempTime := Format(DateTime, 0, 9);
            TempTime := DelChr(TempTime, '=', '-:.TZ');
            Evaluate(UtcTime, TempTime);
Sign In or Register to comment.