How to calculate the current UTC Time Zone from Navision?

There was a case where i need to get this kind of output hh:mm:ssZ where Z stands for UTC Time Zone (20:15:00+0200) to the external system for integration.

For Instance, the current time zone in the system is UTC +02:00 and we need to get this value (+0200) from Navision. There are no predefined functions to get this value so for that i have created a new function GetUTCOffset which can be used to get the UTC offset.

LOCAL PROCEDURE GetUTCOffset@5() : Text;


lLocalTime@1004 : Time;

lUTCTime@1000 : Time;

lDateTimeTxt@1003 : Text;

lTimeTxt@1001 : Text;

lTimeDiffTxt@1002 : Text;

lSign@1005 : Text;




lDateTimeTxt := FORMAT(CREATEDATETIME(TODAY,lLocalTime),0,9);

lTimeTxt := COPYSTR(lDateTimeTxt,STRPOS(lDateTimeTxt,’T’) + 1);

lTimeTxt := COPYSTR(lTimeTxt,1,STRLEN(lTimeTxt) – 1);


lTimeDiffTxt := FORMAT((lLocalTime – lUTCTime) / 3600);

lSign := ‘+’;

IF lTimeDiffTxt[1] = ‘-‘ THEN BEGIN

lSign := ‘-‘;

lTimeDiffTxt := DELCHR(lTimeDiffTxt,’=’,’-‘);



EXIT(FORMAT(lLocalTime,0,lSign + ‘<hours24,2><minutes,2>’));


If the Time zone is UTC +02:00 then the Output will be +0200
If the Time zone is UTC +02:00 and we have DST (Daylight Saving Time) then the Output will be +0300

I have formatted the final output of the Time to remove the “:” using the below code.
FORMAT(lLocalTime,0,lSign + ‘<Hours24,2><Minutes,2>’)
You can format the output per your requirement.

Please do let me know if in case there are some issues & suggestion about the code & approach. Thanks


4 thoughts on “How to calculate the current UTC Time Zone from Navision?

  1. Thanks for the code. Haven’t run into a problem, I would suggest making a few changes to prevent problems with different localized formatting.

    lLocalTime := 1000T;

    I think the evaluate function takes into account system settings about localized time formats. It may fail depending on which country you are. Using 1000T is universal. I changed time from 17:00 to 10:00 because it looks safer to me to not run into problems when times are defined with AM/PM.


    • Hi JP,
      Thanks for the review. I have tested the code with both the values (17:00 & 1000T) with different regional settings and it works fine,as the time is parsed based on the regional settings.


  2. I’m no longer positive where you’re getting your information, but great topic. I must spend some time learning more or working out more. Thanks for fantastic info I used to be searching for this info for my mission.


  3. Thanks for another excellent post. The place else may just anybody get that type of info in such a perfect way of writing? I’ve a presentation next week, and I’m at the search for such info.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s