I am using a calendar control with ASP.NET to fill in a text box with the selected date.
Here is the code I use to get the date into the text box:

Private Sub Calendar_SelectionChanged(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles calendar.SelectionChanged
        calendar.Visible = False
        
        duedate.Text = calendar.SelectedDate.ToShortDateString()
        Dim div As System.Web.UI.Control = Page.FindControl("divCalendar")
        
        If TypeOf div Is HtmlGenericControl Then
            CType(div, HtmlGenericControl).Style.Add("display", "none")
        End If
       
    End Sub

When a date is selected, it goes into the text box and looks like this:
7/3/2009.

The problem is that when I view the gridview that returns the content inserted from that calendar control/text box combo, it looks like this:
Jul 23 2009 12:00AM

I am OK with it showing "Jul 23 2009" but I do NOT want it to show the time on there! The db field is char20.

Any tips really appreciated!

You are storing date value as a string of characters in the backend database.

Check the date value stored in the database has time part.

If it has time part, then you need to format the calender value before inserting into database.

In case anyone is wondering, I solved this issue. I go ahead and store the date as shortdate in a string via ToShortDateString(), but when I run the query to pull the date, I use this:

SELECT Convert (Varchar, [datefield], 101) FROM tablename

Hope this helps someone else like it helped me.

Hi,
You can use the itemtemplate to display the date according to ur format.
the following is code snippet... Hope it help u..

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
            <Columns>
            <asp:TemplateField>
            <ItemTemplate>
            <asp:Label ID="Label2" runat="server" Text='<%#Bind("Joining_Date","{0:dd/MM/yyyy}")%>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
             
            </Columns>
        </asp:GridView>

Best Regards,
Phani Chavali

okey my friend you need little formating just like kameshwari suggested....

hope it helps..!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.