Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to remove time from datetime in vb.net inside a datagrid
Posted
Comments
Jignesh Khant 19-Jun-13 1:21am    
To get only Date part from DateTime You can use .ToShortDateString() function.

You write code to show just the bit you want to see. If this is ASP.NET, you create a template which defines the code used to show the element, I'm not sure about winforms. As someone said 'ToShortDateString' will do it.
 
Share this answer
 
hi,
you need something like this.

VB
Dim dt As DateTime = DateTime.ParseExact(yourObject.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)

Dim s As String = dt.ToString("dd/M/yyyy")


regards
Sarva
 
Share this answer
 
A lot depends on how you are binding your data to the grid. If you have AutoGenerateColumns = False, it is pretty easy:
XML
<Columns>
    <asp:BoundField DataField="DateSent" HeaderText="Date" ReadOnly="true" 
                HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" />
</Columns>
This tells ASP to use the specified format string. HtmlEncode needs to turned off for this to work, otherwise ASP can re-interpret your format string in ways leading to undesirable results.

There are other ways you can do this, but this will probably meet your needs.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900