Don't quote me on this!

by Michael S. Kaplan, published on 2006/09/05 07:08 -07:00, original URI:

So you take some simple bit of managed code using DateTime.Parse, like the following:

using System;

public class Test {
    public static void Main() {
        DateTime dt1 = DateTime.Parse("3/15/2007");
        DateTime dt2 = DateTime.Parse("'3/15/2007'");

Now if you compile this with version 1.1 of the .NET Framework and run it, the output is as follows:

3/15/2007 12:00:00 AM
3/15/2007 12:00:00 AM

And if you do the same with version 2.0 of the .NET Framework and run it, and you escape out of the error dialog that comes up, the following output happens:

3/15/2007 12:00:00 AM

Unhandled Exception: System.FormatException: String was not recognized as a valid DateTime.
   at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
   at System.DateTime.Parse(String s)
   at Test.Main()

Yikes! I guess you really can tell people not to quote you on this one, huh? :-)


This post broughtto you by (U+0931, a.k.a. DEVANAGARI LETTER RRA)

no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day