C# How to Insert a Zero date?
c#, database, date, exception
Solution
No, because there is a min value of DateTime and thats certainly not 0. You could use a nullable DateTime and make your field nullable in the database as well.
To see the minimum value you can try this for academic purposes:
// Define an uninitialized date.
DateTime date1 = new DateTime();
Console.Write(date1);
if (date1.Equals(DateTime.MinValue))
Console.WriteLine(DateTime.MinValue.ToString() + " (Equals Date.MinValue)");
// The example displays the following output:
// 1/1/0001 12:00:00 AM (Equals Date.MinValue)
More info on nullable types: http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.80).aspx
Problem
I need to convert a zero string say "00000000" into date and insert in DB but I cannot use ``` Date.ParseExact("00000000","yyyymmdd",null); ``` Also tried with `CultureInfo.InvariantCulture` Getting the following Exception: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.