Hi RichardSa,
Please refer to a sample below.
You can refer to the article below for checking date and time format strings.
Custom date and time format strings
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="lblBirthDate" 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.BindGird();
}
}
private void BindGird()
{
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);
lblBirthDate.Text = Convert.ToDateTime(dt.Rows[0]["BirthDate"]).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.BindGird()
End If
End Sub
Private Sub BindGird()
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)
lblBirthDate.Text = Convert.ToDateTime(dt.Rows(0)("BirthDate")).ToString("MMMM dd, yyyy h:mm tt") & "."
End Using
End Using
End Using
End Using
End Sub
Output
December 08, 1948 12:00 AM.