ASP.NET DateTime.Parse oddness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Kenny

    #1

    ASP.NET DateTime.Parse oddness

    Dear All,

    I have a date time validation method thus:

    public static bool IsDate(string date, System.IFormatP rovider provider) {
    try {
    DateTime.Parse( date, provider)
    return true;
    } catch (System.FormatE xception)
    return false;
    }
    }

    This works a treat from a console app:
    e.g. bool b = Utils.IsDate("2 1/2/2003", new CultureInfo("en-GB"));

    However DateTime.Parse throws an exception if the method is called from
    ASP.NET.

    Upon further inspection of the CultureInfo object's
    DateTimeFormat. ShortDatePatter n, it reveals itself as "dd/MM/yyyy" when
    called from the console app but is set to "M/d/yyyy" when called from an
    ASP.NET application.

    Anyone got a clue as to whats happening here. Setting the
    ShortDatePatter n to "dd/MM/yyyy" solved the problem but it is not very
    satisfying when supposedly the culture info object ought to be correct
    for en-GB.

    The environment is XP, VS.NET2002, FW 1.0.3705.288.

    Thanks
    Kevin

Working...