Why when I insert a DateTime null I have "0001-01-01" in SQL Server? Why when I insert a DateTime null I have "0001-01-01" in SQL Server? sql sql

Why when I insert a DateTime null I have "0001-01-01" in SQL Server?


I think this is the value corresponding to the null


If Last_Modified_Date is of type DateTime, you can't have "real null" because DateTime structure - as others already said- is not nullable. So your sample code will not even compile.

If Last_Modified_Date is of type DateTime? (Nullable<DateTime>) your code is correct, but -as @Nikola Dimitroff said in his answer- you can't have "real null" in your database because the default value for DateTime? is 01/01/0001 00:00:00.

The "real null" you are looking for is DBNull.Value, but you can use it only for System.DBNull type; if you assign Last_Modified_Date = DBNull.Value , whatever the type of Last_Modified_Date is, your code will not compile.


When saying you are trying to put a null DateTime, are you using a Nullable<DateTime> (a.k.a DateTime?) or simply DateTime? The latter is a value type and its default value is precisely 01/01/0001 00:00:00