Results 1 to 3 of 3

Thread: String format question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    211

    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

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width