Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Date Field

Status
Not open for further replies.

Tim2525

Technical User
Feb 7, 2005
51
US
Hi All,

Calling a date field form Access and loading it to a table row via:

<%# DataBinder.Eval(Container.DataItem, "eventBeginDate") %>

It displays mm/dd/yyyy hh:mi:ss AM. I want it to display only mm/dd/yyyy. How would I format this?

TIA,

Tim
 

Hi,

<%# Format(DataBinder.Eval(Container.DataItem, "eventBeginDate"), "MM/dd/yyyy") %>

Note the case of 'MM'

J

----------------------------------------------------------------------------------------
Try saying Tek-Tips Tek-Tips Tek-Tips more than 3 times in a row....no chance!
 
I need to do the same thing and what you describe works great, except if the value being returned is NULL. How do I get around this?
 
Try
<%# DataBinder.Eval(Container.DataItem, "eventBeginDate", "{0:MM/dd/yyyy}") %>

Null should evaluate to String.Empty
 
Very nice! If I need to format other fields such as a Phone Nbr, would I use the {0: to handle those Nulls as well?
 
Supposed to. DataBinder.Eval is a super fat way to format data. By fat I mean it uses reflection and can slow things down if abused.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top