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?
Monica PConnect With a Mentor Software 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

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>


Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.