locked
Problem Formatting with ToString RRS feed

  • Question

  • User68971474 posted

    Why doesn't this work?

         x = dateText.ToString("yyyy/MM/dd")

    I don't understand this error message:

         Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.

    This page makes it look like I can do this formatting:

         http://msdn.microsoft.com/en-us/library/5hh873ya(VS.80).aspx

     Where have I gone wrong?

    Friday, September 5, 2008 2:46 AM

Answers

  • User1923880652 posted

    You are doing it wrong.I think dateText is not a DateTime object

    Try convert your dateText into DateTime then apply your format

    something like following 

     x = ((DateTime) dateText.Text).ToString("yyyy/MM.dd"); [Haven't check it though but it will be something like it]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2008 5:32 AM
  • User-990694832 posted

    If x is a string

    use:

     x = string.format({ },x)

    OR

    x = string.format({ },datetext.tostring())

    Here is a link to for what to  put in the { }

    http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx

     

    Hope this helps

    DK

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2008 8:42 AM

All replies

  • User1923880652 posted

    You are doing it wrong.I think dateText is not a DateTime object

    Try convert your dateText into DateTime then apply your format

    something like following 

     x = ((DateTime) dateText.Text).ToString("yyyy/MM.dd"); [Haven't check it though but it will be something like it]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2008 5:32 AM
  • User-990694832 posted

    If x is a string

    use:

     x = string.format({ },x)

    OR

    x = string.format({ },datetext.tostring())

    Here is a link to for what to  put in the { }

    http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx

     

    Hope this helps

    DK

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2008 8:42 AM