ADO.net data table is changing time

Viewed 246

I have a strange problem with ado.net data table. I have table named Test in database. It has following data

enter image description here .

I used a data table to fetch this data. Following is my code:

        using (SqlConnection cnn = new SqlConnection(strConString))
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select top 100 idID,dtDate from Test order by idID desc", cnn);
            DataTable dt = new DataTable();
            da.Fill(dt);

//Inserted breakpoint and viewed dt in visualizer
            da.Dispose();
        }

When I see data in quick watch it displays data as shown in following image:

enter image description here

I am not understanding why data table converted a PM time to AM. I tried to display data in html table, just to figure out that it is not a bug in data visualizer or quick watch window. But it is showing time as '15 Nov 2018 10:20 AM' when format "dd MMM yyyy hh:mm tt" is applied.

Any help will be appreciated.

1 Answers

The Visual Studio DataSet Visualizer uses the default date and time display formats specified by Windows. These can be altered in the Date and Time settings page, or in the Date and Time control panel. The "Additional settings..." in the control panel allow you to specify any custom format you like:

Screenshot

Based on what you've described, likely the "Long time" setting has been customized to hh:mm:ss - which is a 12 hour format without showing the am/pm designator. I recommend using either HH:mm:ss or hh:mm:ss tt instead, such that 19:57 doesn't show as 07:57 without you knowing whether it's am or pm.

Related