When you create a VM in Azure it’s always set to the UTC timezone. There are some times when that doesn’t work and it needs to be set for a specific time zone. In a perfect world, the apps could be fixed so that they could deal with the fact that the servers are now in UTC instead of the local timezone. But this isn’t always possible, and the server’s time zone needs to be changed.
The “normal” process to change the timezone for a Windows server doesn’t work as expected. You can change the time zone by right-clicking on the clock and selecting “Adjust Date and Time”. If you change the time zone here, it doesn’t actually do anything (at least it didn’t when I did it). It may also change for a short period of time and then revert back to UTC.
If you use PowerShell to change the timezone the change will stick, even if the VM is deallocated and reallocated.
First, we need to see what the options are for changing the timezone. We can see that by running the Get-TimeZone cmdlet.
Get-TimeZone -ListAvailable
If a list of every time zone possible isn’t helpful (and it probably isn’t) you can filter the list down as you probably know the name of the time zone you’re looking for. My specific client needed a server created in the Pacific Time Zone, So I filtered it down by the word Pacific.
Get-TimeZone -ListAvailable | where ({$_.Id -like "Pacific*"})
Second, we then use the cmdlet Set-TimeZone to change the time zone of the VM. You’ll want to put the ID from the Get-TimeZone cmdlet into the ID parameter of the Set-TimeZone cmdlet.
Set-TimeZone -Id "Pacific Standard Time"
Denny
The post Changing the Time Zine of Azure VMs appeared first on SQL Server with Mr. Denny.
8 Responses
This does not appear to work.
Worked perfectly for me so far! Thanks!
I created a simple function that returns the correct UK time whether in DST or not. It can be adapted for other time zones where DST kicks in.
CREATE FUNCTION [dbo].[f_CurrentDateTime]() RETURNS DATETIME AS
BEGIN
RETURN DATEADD(HOUR,CONVERT(INT,(SELECT is_currently_dst FROM sys.time_zone_info WHERE 1=1 AND NAME = ‘GMT Standard Time’)),GETDATE())
END
Yes! This worked perfectly for me.
(Given that an administrator can do this, why are they locking this down from the VM Windows shell???)
Thank you for your assistance!
Worked a treat – thanks!
Mine must have been prepped with UTC and was causing major sync issues between it and the firewall and the main DC but running this script fixed everything.
Set-TimeZone -Id “GMT Standard Time”
Much appreciated, thanks.
Worked perfectly, thank you!
Worked for me aok.