Question about SqlString

Hi there,

I'm using the datatype System.Data.Common.SqlString to convert "normal" DateTime-values into SQL-compatible values. One thing irritates me: Method "ToSqlString()" always format the Year with 2 digits (yy/MM/dd). Is there any chance to change this behaviour so that ToSqlString() puts the year as a 4-digit number in the output

Thank you.

Reiner



Answer this question

Question about SqlString

  • Computer-Geek

    Were you calling SqlDateTime's ToSqlString() method

    The method actually calls System.DatTime.ToString() with a null IFormatProvider.

    Quote from MSDN:

    The provider parameter is typically a DateTimeFormatInfo object or an instance of CultureInfo, which contains a DateTimeFormatInfo object. If provider is a null reference (Nothing in Visual Basic), the DateTimeFormatInfo associated with the current culture is used. For more information, see CultureInfo.CurrentCulture.

    You can read more about the CurrentCulture property. If you want to change the format in a quicky easy way, just go to the control panel, and change the date format in the regional options.



  • Sameer C T

    Bill,

    I forgot to say that my app is for the Pocket-PC-Platform. I think the problem lies within the OS-Software of the Pocket-PC! The control panel here allows only a short date-format of "dd.MM.yy" (German-culture). You can't choose a format with a 4-digit-year!

    Thanks and greetings from germany!

    Reiner


  • Sriram Krishnan MSFT

    You might change the CurrentCulture Property to "en-US" following the link: http://msdn2.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture(VS.80).aspx

  • Question about SqlString