views:

6454

answers:

4

Date coming out of a database, need to format as "mm/dd/yy"

For Each dr as DataRow in ds.Tables(0).Rows

Response.Write(dr("CreateDate"))

Next
A: 
Response.Write(DateTime.Parse(dr("CreateDate").ToString()).ToString("MM/dd/yyyy"))
Geoff
+2  A: 

Convert.ToDateTime(dr("CreateDate")).ToShortDate()

See the MSDN docs for other functions available from the DateTime datatype, including custom formats available through the 'ToString' function.

Clyde
A: 

Easy:

((DateTime)dr["CreateDate"]).ToString("MM/dd/yyyy")

// I would also check that it isn't dbnull before doing it though

if (! DBNull.Value.Equals(dr["CreateDate"])) // blah blah
stephenbayer
+7  A: 
string.Format( "{0:MM/dd/yy}", dr("CreateDate") )

Edit: If dr("CreateDate") is DBNull, this returns "".

Greg