Hi RichardSa,
You may need to convert your UTC value to datetime and then use the ToLocalTime() method to convert the UTC method to localTime.
Please refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:Label ID="lblUtc" runat="server"></asp:Label>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Bind();
}
}
private void Bind()
{
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("Select Top 1 BirthDate from Employees",con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
lblUtc.Text = Convert.ToDateTime(dt.Rows[0]["BirthDate"]).ToLocalTime().ToString("MMMM dd,yyyy h:mm tt") + ".";
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.Bind()
End If
End Sub
Private Sub Bind()
Dim constring As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("Select Top 1 BirthDate from Employees", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
lblUtc.Text = Convert.ToDateTime(dt.Rows(0)("BirthDate")).ToLocalTime().ToString("MMMM dd,yyyy h:mm tt") & "."
End Using
End Using
End Using
End Using
End Sub
Output
December 08,1948 5:30 AM.