0

While reading data of sql server from gridview ,the date column adds an extra 12:00:00 AM to the end of the date.

eg:9/29/2013 12:00:00 AM

In the gridview it shows this way, but i only have a date type date saved in the sql table.

I need that to be only 9/29/2013.

same thing happened while reading and displaying that in a textbox , but it could be solved this way

DateTime date =Convert.ToDateTime(VoucherDetails["voucher_date"]);
                          TextBox3.Text = date.ToString("MM/dd/yyyy");

any solutions for the gridview ?

Huzaim
  • 115
  • 4
  • 13

3 Answers3

0

For the Grid View see datetime format in asp.net gridview. However, you can also change your SQL Query to cast the time columns as a DATE. That will cut off the time portion as well.

Community
  • 1
  • 1
Vulcronos
  • 3,428
  • 3
  • 16
  • 24
0

To format a DATETIME value in a GridView, you can do it like this:

DataFormatString="{0:MM-dd-yyyy}".

Huzaim
  • 115
  • 4
  • 13
0

Here's an example of a bound field.

    <asp:BoundField DataField="TheDateField" HeaderText="HeaderText" 
                DataFormatString="{0:MM-dd-yyyy}"  />

All you should have to do is add DataFormatString="{0:MM-dd-yyyy}" to your bound field.

Keefe Higgins
  • 177
  • 2
  • 10