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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to format date within datalist 1

Status
Not open for further replies.

drew10

Programmer
Feb 26, 2002
123
US
I have a datalist that displays dates. In the database, the dates are show as '9/29/2002', however when the datalist is populated the dates are formatted so that it reads '9/29/2002 12:00:00 AM'. Does anyone know how I can format the date to read just '9/29/2002'? Thanks in advance for any help.
-Drew10
 
If you aren't using VS then your databinder statment needs to look something like this.
<%# DataBinder.Eval(Container, &quot;DataItem.Date&quot;, &quot;{0:D}&quot;) %>

Where the {0:D} means the long date format Friday Sept 27 2002. You could also use {0:d} which is the short date format 09/27/2002.

Another option is to introduce a call to a function before the databinder like so.
<asp:Label runat=&quot;server&quot; Text='<%# FormatMyDate(DataBinder.Eval(Container, &quot;DataItem.Date&quot;)) %>'>
In your code behind page you have write the function

Protected Function FormatMyDate(ByVal obj As Object) As String
Dim output As String

If IsDBNull(obj) Then
output = String.Empty
Else
'put your formating code here.
End If
Return output
End Function


HTH That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top