I have a column called CreateDate (DateTime) in table1 in SQL Server 2008.
With a stored procedure I try to update CreateDate as parameter, like this:
SqlParameter spdtCreateDate = cmd.Parameters.Add("@dtDreateDate", SqlDbType.DateTime);
spdtCreateDate.Value = dtCreateDate;
From an application in C# I send CreateDate='6/29/2012 12:00:00 AM' but when I check in database the CreateDate is set as 2012-06-28 23:00:00.000 instead as 2012-06-29 00:00:00.000
Can anyone tell me what happen?
How can I solve this problem?
The SQL Server
datetimetype does not include any time zone information. Because of this, the SQL Server client libraries assume that you will always want to store local times in it. If you have set your .NETDateTimevalue to something with the UTC time zone, then the SQL Server client will helpfully convert it to local time for you before storing it.Possible solutions:
DateTimevalue to specifyDateTimeKind.UnspecifiedorDateTimeKind.Local.datetimeoffset(SQL 2008 or above).