Convert JSON Date to DateTime string in ASP.Net using C# and VB.Net

on May 18, 2021 11:08 PM

Date(1239018869048)\/" convert in to date Jquery ajax Json will return this format

This format display in grid but I want to display date

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on May 20, 2021 08:10 AM
on May 20, 2021 08:11 AM

Hi kas12345,

You have to set JsonSerializerSettings.DateFormatString to your desired format.

Check this example. Now please take its reference and correct your code.


For this example I have used of Northwind database that you can download using the link given below.

Download Northwind Database


<table class="tblEmployees">
<script type="text/javascript" src=""></script>
<script type="text/javascript">
    $(function () {
            type: "POST",
            url: "Default.aspx/GetEmployees",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var employees = JSON.parse(response.d)
                var rows = '';
                for (var i = 0; i < employees.length; i++) {
                    var id = employees[i].EmployeeId;
                    var name = employees[i].FirstName;
                    var dob = employees[i].DOB;
                    rows += "<tr><td>" + id + "</td><td>" + name + ' ' + "</td><td>" + dob + "</td></tr>";
                $('.tblEmployees tbody').append(rows);



using System.Data;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using Newtonsoft.Json;


Imports System.Data
Imports System.Web.Services
Imports System.Configuration
Imports System.Data.SqlClient
Imports Newtonsoft.Json



public static string GetEmployees()
    string query = "SELECT EmployeeID,FirstName,BirthDate FROM Employees";
    string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
        using (SqlCommand cmd = new SqlCommand(query))
            List<EmployeeModel> employees = new List<EmployeeModel>();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            using (SqlDataReader sdr = cmd.ExecuteReader())
                while (sdr.Read())
                    employees.Add(new EmployeeModel
                        EmployeeId = Convert.ToInt32(sdr["EmployeeID"]),
                        FirstName = sdr["FirstName"].ToString(),
                        DOB = Convert.ToDateTime(sdr["BirthDate"])
            var jsonSettings = new JsonSerializerSettings();
            jsonSettings.DateFormatString = "dd/MM/yyyy";

            return JsonConvert.SerializeObject(employees, jsonSettings);

public class EmployeeModel
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public DateTime? DOB { get; set; }


Public Shared Function GetEmployees() As String
    Dim query As String = "SELECT EmployeeID,FirstName,BirthDate FROM Employees"
    Dim constr As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand(query)
            Dim employees As List(Of EmployeeModel) = New List(Of EmployeeModel)()
            cmd.CommandType = CommandType.Text
            cmd.Connection = con
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                While sdr.Read()
                    employees.Add(New EmployeeModel With {
                        .EmployeeId = Convert.ToInt32(sdr("EmployeeID")),
                        .FirstName = sdr("FirstName").ToString(),
                        .DOB = Convert.ToDateTime(sdr("BirthDate"))
                End While
            End Using

            Dim jsonSettings = New JsonSerializerSettings()
            jsonSettings.DateFormatString = "dd/MM/yyyy"
            Return JsonConvert.SerializeObject(employees, jsonSettings)
        End Using
    End Using
End Function

Public Class EmployeeModel
    Public Property EmployeeId As Integer
    Public Property FirstName As String
    Public Property DOB As DateTime?
End Class


Refer below links for more details.

Serialize DateFormatString

Serializing Dates in JSON