none
SQL Server Create data about time always get "0001/1/1 0:00:00" RRS feed

  • Question

  • In my ASP.NET project,there is a filed about time in a data table (SQL Server 2008).Its type is "datetime",default value "getdate()". It worked well. While I change the type ,and use "datetime2".I think it's a good idea. But when I debug,its value is always "0001/1/1 0:00:00". I do not know where is wrong.I hope someone can help me solve this problem. Thank you!( Sorry,my English is poor ;) ) 
    • Moved by Bob Beauchemin Wednesday, June 19, 2013 4:02 AM Moved to a more relevent forum. You might also repost to ASP.NET forum
    Tuesday, June 18, 2013 5:50 PM

All replies

  • The default value (default constraint in SQL Server) is stored in the database only when the column is not specified in an INSERT statement.  If datetime2 value '001-01-01 00:00:00' is being stored is, that means the application is including the datetime2 column in the insert statement and passing either an empty string or a DateTime instance without an assigned value.

    If you need more help, please post the relevant .NET code.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Thursday, June 20, 2013 10:41 AM