Displaying my dates without the time with # DataBinder.Eval(Container.DataItem, etc

andycharger

Centurion
Joined
Apr 2, 2003
Messages
152
Im trying to dsplay my dates from my SQL SERVER dataase in my .net page

Im using the following way of displaying it:

Visual Basic:
<%# DataBinder.Eval(Container.DataItem, "phone_date") %>

The problem is, it is displaying the date in a textbox as follows:
03/12/2003 00:00:00
I dont want the time bit appearing so is there a way to stop it showing?

Thanks

Andy
 
I'm sorry but that solution won't fly if the date is in any other format, you neet to apply a format style to the column or format the column in your select statement.
 
Is it something like this:

<%# Left(DataBinder.Eval(Container.DataItem, "phone_date").ToString(),10) %>

I used the previous method myself but I got the data in the String format. So, I didn't have any problem.

SJ
 
Here is an example I quickly grabbed of formating a date field inside a datagrid column;

<asp:BoundColumn HeaderText="Order Date" DataField="OrderDate" DataFormatString="{0:MM-dd-yy}" ItemStyle-HorizontalAlign="Center"/>
 
Use DateTime.Parse() to turn your string into a DateTime variable, and then use the
ToShortDateString() to return a string of just the date.

Code:
<%# DateTime.Parse(DataBinder.Eval(Container.DataItem, "phone_date")).ToShortDateString() %>
 
Back
Top