Converting UTC DateTime to Local DateTime (MSSQL + JS)

Sithum Meegahapola
2 min readFeb 7, 2022

This article will show you how to convert UTC date time that saved in MSSQL Server within a normal DateTime type Column to Local Date Time from Java Script.

This is how UTC Date Time saved in the MSSQL database table.

Screen shot from MSSQL DB table DateTime column

It is same as a normal Date Time that there is no any section that saying this is UTC converted Date Time. So if you get this data to your front end and asked to convert it to local Date Time it will show the same Date Time that you see in above screen shot with the conversion you have chosen.

So, Below are the steps you need to follow to convert this UTC converted Date Time into your local Date Time from JavaScript .

As in the screen shot,

Line #2 will have the String with the Date Time that you have in the MSSQL Server database table (UTC Date Time).

In line #5 you need to create a Date by adding “+00:00” to the end of date string that we have the UTC date time from the server. After that you have a variable with the Date that mentioning it is in the UTC Date Time.

As in line #8 you can convert it into Local Date Time by using the “.toLocalString();” and it will return the actual Date Time for your local time zone.

This is one of a scenario i gone through and feels like it will be a help for you as well.

--

--