I’m working on a project where I need to store UTC time in a SQL Server datetime column. The tricky part is that the data comes from JavaScript in two parts:
-
A UTC string made with
(new Date()).toUTCString()
. It looks like this:Thu, 03 Mar 2016 06:19:11 GMT
-
A timezone offset created using
new Date().getTimezoneOffset()
. For example:-330
I’m pretty new to dealing with timezones and UTC, so I’m not sure how to combine these two pieces of info and save them correctly in SQL Server. Any tips on how to handle this would be super helpful!
Here’s a dummy code snippet to show what I’m working with:
function getTimeData() {
const utcString = (new Date()).toUTCString();
const tzOffset = new Date().getTimezoneOffset();
return { utcString, tzOffset };
}
// Now I need to send this to SQL Server somehow
How can I take this JavaScript output and turn it into something SQL Server can understand as UTC time?