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.