Azure SQL Database - How to change time zone settings? - azure

My Azure server is hosted in East US. In the SQL DB, when I use getdate(), it returns UTC time. But I need to get EST time. How can I achieve it? Is there any setting I need to change?

The easiest way to get the current time in the US Eastern time zone is:
select SYSDATETIMEOFFSET() AT TIME ZONE 'Eastern Standard Time'
This returns a datetimeoffset and accounts correctly for daylight saving time.

OP has developed a function:
FN_GET_EST(GETDATE()).
CREATE FUNCTION FN_GET_EST(#p_in_date as datetime) returns DATETIME
as
begin
DECLARE #dt_offset AS datetimeoffset
SET #dt_offset = CONVERT(datetimeoffset, #p_in_date) AT TIME ZONE 'Eastern Standard Time'
RETURN CONVERT(datetime, #dt_offset);
end

Related

ADF convertTimeZone Invalid Timezone ID

I encounter this weird issue related on using convertTimeZone function in ADF.
convertTimeZone function expect 4 params which are timestamp string, source timezone, new timezone, date format
Refer to this document [https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#convertTimeZone]
I keep receiving error
the function 'convertTimeZone', the value provided for the time zone id 'Singapore Standard Time' was not valid. "
I double check it whether the timezone I provided is in the microsoft time zone list
Refer to this document: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones?view=windows-11
Which in this case is in the list. Any thoughts?
Use the below expression to convert UTC to 'Singapore Standard Time' time zone.
#string(convertTimeZone(utcnow(), 'UTC','Singapore Standard Time'))
Output:
Reference: Microsoft Time Zone Index Value

Remove timezone completely from SQL Server

EDIT: Some users noted that this is a duplicate of ADO.NET question at
How can I get DateTime data from SQL Server ignoring time zone issues?
Please DO READ my tags, and my codes. This is nodejs question,
that has nothing to do with ADO library whatsoever. It doesn't
even run on Windows. The option noted at the link provided doesn't even exists at mssql-npm
I am creating a database for company attendance, which spans for 3 timezones.
The problem with SQL Server is that I read the working hour differently from each timezone. It registered like 1969-12-31T23:00:00.000Z, and registers as 06:00 for one timeline, and 08:00 for another. I need it to be exactly at 08:00 regardless of timezone. It means, 08:00 at western part of my country, and also 08:00 at eastern part of my country.
When I try to disable UseUTC, nodejs translated my timezone twice. For example, this is when I sent masuk field as 08:00
Sent to server:
Query sent to SQL Server:
UPDATE shift SET name = 'Shift 1', masuk = '2019-10-28T01:00:00.000Z', keluar = '2019-10-28T10:00:00.000Z', tolerance = 15 WHERE id = 1
Received the result back
And shown to the user as:
My country sits at GMT+7 to GMT+9. I don't mind if I have to flatten the timezone. But how to do that? Is there a way to read the time completely ignoring the time zone? It makes my work unnecesarily complicated.
I am using:
SQL Server 2012
Material UI
date-fns
Nodejs 12
mssql module
and this is my code to get the time from user input
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardTimePicker
key={component.field.toString()}
variant="inline"
value={value}
label={component.title}
onChange={this.eventHandler(component.field).bind(this)}
format="HH:mm"
/>
</MuiPickersUtilsProvider>
Thank you for help.
THe database uses time(7) to store the time

Are Alexa skill dates the same in the Service Simulator and the Echo?

My Alexa node.js skill involves getting the current date using "new Date()". In the Service Simulator the date returned is UTC. But I need the time in "America/New_York" -- my skill is local to New York. So I can convert the time zone, no problem. But I'm wondering whether this will get the same result when I deploy the skill. That is, does the Date() function on the actual Service convert to local time from UTC? If it does, then I will need some way of determining in my code whether I am in the Service Simulator or the actual Service, and converting to New York time in my accordingly.
Thank you.
From the documentation for Date
If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.
So depending on the system settings the timezones can be different.
To overcome this you can use UTC date everywhere and then simply convert the timezone where needed.
// date with some timezone depending on system
let date = new Date();
// date in UTC
let utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
Note: utcDate will still be in the system timezone, but the actual value it holds will represent the correct date and time in UTC.

how to get local timezone on azure service

I have a service running on azure cloud. This service runs in every 1 min and picks some files from ftp server. These files have Datetime fields and not datetimeoffset, which when read by service become UTC dates. These FTp servers are in different timezone.
For example one of the ftp is in GMT timezone. Say file has date 12/5/2015 time 12:15. This is read by service as UTC(because no timezone received) and stored in database as 12/5/2015: 12:15:00 +0:00, while it should be
12/5/2015: 11:15:00 +0:00.
I still want to save date in database as UTC, need a way to get these ftp timezones, so I can parse date correctly.
The problem is we can't make any changes in file.
Is there any way cloud sevice can get timezone for these FTP?
There's nothing Azure specific here for what you want, but you can roll your own solution.
You'd have to do some fancy stuff to guess the timezone of an FTP server, which would involve doing a DNS lookup of the server to figure out it's IP address, mapping that IP address to a city, and looking up the city's Time Zone. You could do that but it would be error prone.
There's an easier and more reliable option. It sounds like you your list of FTP servers is fairly static. You can just create a lookup table that says which timezone each FTP server is in, and use that table to figure out which timezone offset you should use.
Best practice: Server-side code should never depend on the time zone or culture settings of the server that is hosting the code. Instead, these concerns should be addressed in the code itself.
For example, assuming your service is written in C# / .NET, you might have code like this:
string s = "12/5/2015 12:15 PM"; // from the file
DateTime dt = DateTime.Parse(s);
DateTime utc = dt.ToUniversalTime();
The above code relies on the server's local time zone during the ToUniversalTime function. It also relies on the server's culture during the Parse function.
Instead, you should have knowledge of the time zone and culture of the input file. For example:
string s = "12/5/2015 12:15 PM"; // from the file
DateTime dt = DateTime.ParseExact(s, "M/d/yyyy h:mm tt", CultureInfo.InvariantCulture);
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
DateTime utc = TimeZoneInfo.ConvertTimeToUtc(dt, tz);
This code supplies the CET/CEST time zone, and also provides an exact input format using the invariant culture.
Late post, but thought I would post my solution to help anyone else:
TimeZone localZone = TimeZone.CurrentTimeZone;
var cetZone = TimeZoneInfo.FindSystemTimeZoneById(localZone.StandardName);
var cetTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cetZone);
DateCreated = Convert.ToDateTime(cetTime.ToString());
In my instance, the localZone.StandardName gives me "South African Standard Time", which I believe is GMT+2.
Hope this helps someone else out!
Cheers

Google Tasks Migration to Exchange account

I have retrieved Tasks from my Gmail account using OAuth 2.0 Dot Net Google client library (https://developers.google.com/api-client-library/dotnet/apis/tasks/v1). When I save any of these tasks to my exchange account using Microsoft.Exchange.WebServices Dot Net library, the date of Task is adjusted automatically, although the time zone of Gmail account and exchange account are same i.e. Central Time (US & Canada). I want to prevent this automatically adjustment in Task date.
Can any one help?
Make sure you set the time zone on the ExchangeService object to the user's time zone. https://msdn.microsoft.com/EN-US/library/office/dn789029(v=exchg.150).aspx
I have solved the problem by using Calendar time zone. Basically, Google Calendar has time zone information. I retrieved time zone information from primary calendar and then before saving Task to Exchange account, I converted due date to UTC with following C# code
if (task.Due.Value.Kind == DateTimeKind.Local)
{
dueDateUTC = task.Due.Value.ToUniversalTime();
unspecifiedKindDate = new DateTime(dueDateUTC.Year, dueDateUTC.Month, dueDateUTC.Day);
dueDateUTC = TimeZoneInfo.ConvertTime(unspecifiedKindDate, Utility.OlsonTimeZoneToTimeZoneInfo(timezone), TimeZoneInfo.Utc);
}
This code first of all find out that whether Task due date is in local time zone or not. If it is in local time zone then due date is converted into UTC. After converting into UTC, a unspecified kind datetime object is created through following code
unspecifiedKindDate = new DateTime(dueDateUTC.Year, dueDateUTC.Month, dueDateUTC.Day);
This unspecified kind datetime is then again converted to UTC with the help of following code
dueDateUTC = TimeZoneInfo.ConvertTime(unspecifiedKindDate, Utility.OlsonTimeZoneToTimeZoneInfo(timezone), TimeZoneInfo.Utc);
Now this "dueDateUTC" object is used to save Task information into Exchange account. On saving Task, Exchange server automatically converts dueDateUTC to mailbox time zone and this was desired. :)

Resources