string asofdate = db.ExecuteScalar(cmd).ToString();
Upon executing the above line of code, I get data in the format of
09/30/2010 12:00:00AM
But I want to format this into 09-Sep-2010.
How can I do this?
thanks
nath
Printable View
string asofdate = db.ExecuteScalar(cmd).ToString();
Upon executing the above line of code, I get data in the format of
09/30/2010 12:00:00AM
But I want to format this into 09-Sep-2010.
How can I do this?
thanks
nath
Supply a custom format string as a parameter to the ToString method. The reference for the format strings can be found here:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Just note that ExecuteScalar returns an Object reference and Object.ToString doesn't accept arguments. What you want to call is DateTime.ToString, so you'll need to first cast the returned value as type DateTime. If the result might be NULL, you'll have to allow for that too.