Time zones usage in Microsoft Dynamics NAV web services

In Microsoft Dynamics NAV 2009 R2 we have new feature named "Defining the Time Zone for Web Services". You can read about it at http://msdn.microsoft.com/en-us/library/gg502505.aspx . The same feature exists in Microsoft Dynamics NAV 2009 SP1 since build 31926 with KB 2443436.  However we have few support requests when NAV developers or users don't know about this feature availability or don't know how to use it.
I will try to describe in samples what results we have with different sets.

This feature is important only when you are using date; time or datetime fields and functions to create it. So I created table which has date; time; datetime and description fields

I created codeunit which will be published to Web Service and we'll call function cr_dateTime to create date = Jan 10th 2011
Time = 3:00:00 PM
And DateTime from these values.

In Visual Studio I created C# application which just runs function from codeunit.


WSDT is reference to my Web Service codeunit


And now came main feature point: In CustomSettings.config file could be added new key: "WebServiceDefaultTimeZone".
Actually there could be few possibilities:
1. Key doesn't exists. Then WS works as before this feature implementation - WS uses UTC time zone
2. Key value is empty. The same as point 1 - uses UTC time zone
3. Key value is "UTC". This is default value in Dynamics NAV 2009 R2. WS uses UTC time zone.
4. Key value is "Server Time Zone". WS will work using server computer default time zone. If you are using any time/date functions in code then this key will get you the same results as code running on Classic Client; RTC or NAS.
5. Use any other value from available time zones constants. You can find it at Microsoft Time Zone Index Values at http://support.microsoft.com/kb/973627 . Actually these values already must be in windows registry and if it doesn't exists there, you will have error during WS start.


Here are few of possible time zones values.


My local time zone is "FLE Standard Time"-GMT+02:00, and we need to remember this during execution. So I'm running function from codeunit using different sets.

  • 1. Entry created by directly codeunit run (the same as we would run CC; RTC or NAS). We have value directly what was expected - 3:00 PM. But look in values we have directly in SQL table (second table picture) where NAV stores UTC DateTime. We see that NAV accepted that 3:00PM is local time, so it subtracted 2 hours (according time zone) and wrote 13:00 to SQL (UTC time)
  • 2. Entry created by WS when there is no new featured key added (the same as empty key value or value "UTC"). Date time now is different; NAV shows 5:00 PM but SQL shows 15:00. Situation was that WS thought that time is already UTC and just wrote what it got and NAV adding my time zone (+2:00) to have "local time"
  • 3. Entry created by WS when key value is "Server Time Zone". Situation is the same as in point 1: WS received 3:00 PM, calculated UTC (-2:00), stored it to SQL and NAV shows again local time calculating it from UTC.
  • 4. Entry created by WS when key value is "Central Standard Time". This time zone is GMT-06:00. So WS calculated UTC from 15:00 + 06:00 = 21:00 and wrote it to SQL. NAV calculates and shows my local time 21:00 + 02:00 = 23:00 = 11:00 PM.


 So it looks everything clear now. However there are few more points need to be mentioned.
In my samples I created datetime using function CREATEDATETIME(011011D,150000T); But what will happen if I will use function CREATEDATETIME(TODAY,TIME);? Problem is that TIME function also knows about time zones and will use it during calculation.
Look, here is example using different "WebServiceDefaultTimeZone" values, and I set to t_time value from TIME and to d_date value from TODAY. When I did tests it was 11th of Jan 2011 about 10:15 AM morning.

You see differences?

1st entry is by direct codeunit run - my correct time.
2nd entry without key and here comes UTC time.
3rd entry with "Server Time Zone" - my correct time
4th entry with "Standard Central Time" (GMT-06:00) - correct time in that zone (10:21-2:00-6:00).

But look to date_time field - it shows correct time for my zone even everything is different. Why? 


It is because datetime uses UTC - look what SQL shows.
1st row - my local time 10:15 - 2:00(my time zone) = 08:15 UTC.
2nd row - UTC time now is 08:18 and the same is in datetime.
3rd row - the same as in 1st row
4th row - local time in that time zone is 2:21 AM; UTC time is 8:21 AM and this is in SQL.


I hope this is clear.
At least you can play with some samples and you will find the way you need to have as result.

These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.

Best Regards
Gedas Busniauskas
Microsoft Lithuania
Microsoft Customer Service and Support (CSS) EMEA

Comments (5)

  1. Elwin says:

    Thanks for this information. This is exactly the problem I have.

    At this moment we are working with NAV 2009 SP1 build 29626. Your article says the problem can be solved by using a hotfix to build 31926.

    Unfortunally I can't find a hotfix to upgrade to build 31926. The last build on partnersource is 31861.

    How can I download the changes to upgrade to build 31926?

    Thanks in advance.

  2. Hotfixes download says:

    Best way to get hotfix is create support request to NAV support team – it will be free of charge and our guys will recommend best way to apply hotfixes.

    Or you can download it from support.microsoft.com/…/KBHotfix.aspx, but then all good/bad results are on your reponsibilities.

    Personally i'm recommending to use NAV 2009 R2.


  3. Craig says:

    Hi Gedas. Thanks for the post.

    Did you find you had any issues with caching of the values that you set in "WebServiceDefaultTimeZone"?

    I find if I update the "WebServiceDefaultTimeZone" value, save the config file, stop and restart the webservice, then run my c# application, the results remain the same until I actually restart my entire machine.


  4. Craig says:

    Hi Gedas. You note that "Problem is that TIME function also knows about time zones and will use it during calculation."

    The TODAY function is also time zone aware which has become a problem for me in New Zealand (we are 12 hours ahead of UTC) because if I create and post a journal via the webservice in the morning, the register is shown as having been created the day before (e.g. 10 Jan 08:00 – 12 hours = 09 Jan 20:00), as it is populated using TODAY.



  5. Few Add's says:

    Hi Craig

    Thank you for your comments…

    Actually i forgot to mention even i was planning…

    1. WS(Web Service) isn't alone service. It can't work without NST (NAV service Tier). Actually WS just publish data to web as all processing is provided by NST. So required way to restart both services is: stop WS; restart NST; start WS. These steps must be done after any changes in config file, security modify and etc.

    2. New Zeland time…?? Needs to make more tests. What is value for key "WebServiceDefaultTimeZone"? Maybe we forgot something here…


Skip to main content