|
-
Feb 8th, 2011, 06:46 PM
#1
Thread Starter
Addicted Member
String format question
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
-
Feb 8th, 2011, 08:33 PM
#2
Re: String format question
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
-
Feb 8th, 2011, 10:49 PM
#3
Re: String format question
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|