Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:27:38+00:00 2026-05-19T01:27:38+00:00

I have data stored in a SQL database that I’m attempting to read into

  • 0

I have data stored in a SQL database that I’m attempting to read into an ASP.NET MVC application. I can get the data just fine – but the datetimes are not translating into anything useful.

Here’s what I have so far (some data redacted as “…”):

    public JsonResult GetXYZByStatusJson()
    {
        var sqlConn = new SqlConnection(...);
        var command = new SqlCommand("...", sqlConn);

        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.AddWithValue("@status", 0);

        sqlConn.Open();
        var sqlResult = command.ExecuteReader();

        var collection = new Collection<Object>();
        while (sqlResult.Read()) 
        {
            collection.Add(new XYZ(
                ...
                Convert.ToDateTime(sqlResult["DateSent"]),
                Convert.ToDateTime(sqlResult["DateDue"]),
                ...
                ));
        }

        sqlResult.Close();
        sqlConn.Close();

        return Json(collection);
    }

The resulting JSON is formatted fine, but the dates look like “\/Date(1294120800000)\/”

How do I properly cast the SQL datetime into a C# DateTime? Using .ToString() doesn’t have any affect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:27:38+00:00Added an answer on May 19, 2026 at 1:27 am

    There are nothing wrong with the conversion between Sql Server and C#.

    The problem is how JsonResult formats the string.

    The following SO question shows how you can process it at client side: How do I format a Microsoft JSON date?

    The other way is to create your own alternative to JsonResult

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# Application I am creating that stores all data in SQL
I have data stored in a sqlite3 database and have several places that I
I have a stored procedure in an old SQL 2000 database that takes a
I have a stored proc that processes a large amount of data (about 5m
Say I have a stored procedure that returns data from a SELECT query. I
I have a report that renders data returned from a stored procedure. Using profiler
I have a customer who has legacy data stored in Oracle database. Such data
Ok I have a table in my SQL Server database that stores comments. My
I am trying to build a SQL 2005 database that has a Company data
I have an Access 2003 project in which all data is stored in SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.