GridView Don't want to see time


I have a Bound GridView that shows the results of a query

Select * From Diary

The SQL field is of type "Date" but I still see the following in the Entry_Date column

2013/09/27 12:00:00 AM

How do I pull a query that just shows date
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to format the date:

In your code behind:
 Protected Function fncMyFormatDate(ByVal sDT As String, ByVal sFormat As String) As String
        Dim dt As Date
        ' Function to format any Date field on the form
        If Not IsDate(sDT) Then
            Return ""
            dt = sDT
            Return dt.ToString(sFormat)
        End If

    End Function

Open in new window

In your ASPX :

Use a code similar to this:

<ASP:Label Text='<%# fncMyFormatDate(DataBinder.Eval(Container.DataItem, "DischargedDate").ToString, "MM/dd/yyyy") %>' runat="server" ID="Label4"/>

Open in new window

As you see I format the date that is coming from the DischargedDate field in the database.

Note that my code us for DataGrid. since you are using Gridview you have to use

asp:TemplateField . Code inside asp:TemplateField is similar to the above.
Another example to Gridview:

<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">


        <asp:Label ID="Label1" runat="server" Text='<%#
fncMyFormatDate(Bind("FirstName").tostring(), "MM/dd/yyyy") %>'></asp:Label>


Monica PSoftware DeveloperCommented:
You can format the query to return date :

/*For yyyy/mm/dd format*/

SELECT CONVERT(VARCHAR(10),@DateTime ,111) AS Date

Open in new window

Another way to format the date in Gridview columns are

Incase of the  

BoundField in gridview

<asp:BoundField DataField="Date4" HeaderText="Date4" HtmlEncode="false" DataFormatString="{0:d}" />

Open in new window

<asp:TemplateField HeaderText="Date1">
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date1","{0:d}") %>'/>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.