Introduction
I stronugly believe that in most application we are building, we wowould need to store date and time. in some application, date and time play very important role, for instance: Marshal-similar application which cocould result big impact if date and time are incorrect. in other kinds of application, date and time may not be playing very significant role, for example: some of them is just as informational purpose, when the data is actually inserted in the system.
Regardless the importance level we discussed above, one essential factor that we need to be considered is the timezone of the system. whether setting it as local country timezone or other timezone such as UTC/GMT, We wowould need to determine the it, typically on the server where our application is hosted.
Thus, when we type"Datetime. Now"Inside your code, we shocould be able to get the correct result.
Timezone in Windows azure
No matter which data center we selected in Windows azure (Remember, Windows azure has 6 data centers world wide: 2 in America, 2 in Europe, and 2 in Asia), by default, windows azure VM wocould provide usUTC timezone.
If you are considering migrating your app to Windows Azure, you shocould ask yourself now what timezone your current application set. If it's on UTC, you are safe, nothing to worry.
However, if you are running local time, (for example in Singapore, it's UTC + 8 hour) and you want to ensure the consistency of your current data, then you will need to be cautious. you have "at least" 2 choice to go:
- Use UTC on your app, which mean you wowould need to convert your current date/time data to UTC.
- To set your preferred timezone in Windows azure (it cocould be your local time ).
I bet most of you will decline the first options.
How to Set timezone in Windows azure
Alright, I assume we go with option 2. to set timezone in Windows Azure, I believe there are actually a few waysvia powershell or by modifying registry. honestly, I 've not tried these option on Windows Azure, yet I am not pretty sure if it cocould be applied in Windows azure. but there's an option that is definitely working well.
Okay, there's actually a command utility called"Tzutil"That can be used to change timezone. Please take note that this command is only applicable in Windows 7 and Windows Server 2008 R2.
Tzutil
You may try to run it using your command prompt by typing "tzutil /?" For the information.
To change to your preferred timzeon, simply run the following command.
tzutil /s "Singapore Standard Time"
Run it as start-up task
In Windows Azure, We woshould need to run this commandStart-up task, To ensure that when is starting up, the command will be executed first.
1. To do that, create a empty file (using notepad), and paste the above tzutil Command inside, just save the fileSettimezone. cmdInside your windows azure project.
In your project, ensure that this file is wrongly ded, if not you'll need to include it manually.
2. The next step is to set the properties of this fileCopy always. This is to ensure that the file will be attached ded when project is packaged before deployment.
3. Subsequently, We wowould need to tell windows azure to run the start-up task. This cocould be achieved by adding the following start-up section inside yourServicedefinition. csdefFile.
4. Using Windows Server 2008
R2VM Images
At earlier, I mentioned that the tzutil is only available inWindows 7 and Windows Server 2008 r2. Windows 7 is definitely out of context as there's no such OS in Windows azure.
Windows azure at this moment allows us to choose either Windows Server 2008 or Windows Server 2008 R2. both of them are running on 64 bit architecture.
By default (if you are not modifying anything in your configuration file), Windows Server 2008 will be selected.
In order to use tzutil, We wowould need to set the VM running as Windows Server 2008 R2. to do that, simply navigate toServiceconfiguration. cscfgFile. In the serviceconfiguration section, changeOsfamilyFrom 1 to 2.
* 1 = win 2008, while 2 = win 2008 r2
We woshould also need to set the version of the OS. if you not preferring any OS, you can just simply put * and it will automatically perform update for you when there's patch/New version of guest OS released.
5. Verification
If everything runs well, You shocould be getting your preferred timezone as expected.
Here's how it's look like, when I got Med Remote Desktop to my windows azure VM.
What's next?
In the app level, your are safe since you 've successfully configure the timezone of your VM. But how about database level? What if there's any stored procedure/function inside your code, use "getdate ()" function?
I'll discussed more on this topic in the next post. Stay tune...
Share this post:| Published Sunday, June 26,201 PM by welyfiled under: Windows Azure, SQL Azure, Windows azure platformcomments # managing timezone in SQL azuresunday, July 10,201 1 pm by Wely Lau
In the last post, I showed you how to set timezone in Windows azure. In this post, I wowould like to show