c#datetime到sql,包括秒

时间:2021-05-21 21:32:21

i am trying to save (using linq) the date and time to an SQL field (datetime data type) using Datetime.Now but the seconds are not coming through. Does anyone know how to rig that up?

我试图使用Datetime.Now保存(使用linq)SQL字段(日期时间数据类型)的日期和时间,但秒不会通过。有谁知道如何装备?

Ta.

2 个解决方案

#1


It works fine for me with DateTime.Now. I only have problems with millisecond precision due to the different way how SQL server stores the date.

DateTime.Now对我来说很好用。由于SQL Server存储日期的方式不同,我只有毫秒精度问题。

What type has the SQL table column for your date? Can it store seconds?

您的日期的SQL表列是什么类型的?可以存储秒数吗?

#2


As i was using a smalldatetime data field initally i forgot to update my data access layer (linq) after i changed it to datetime. Updating the linq data context has solved my problem. Thanks all.

因为我最初使用的是smalldatetime数据字段,所以在将其更改为datetime之后忘记更新我的数据访问层(linq)。更新linq数据上下文已经解决了我的问题。谢谢大家。

#1


It works fine for me with DateTime.Now. I only have problems with millisecond precision due to the different way how SQL server stores the date.

DateTime.Now对我来说很好用。由于SQL Server存储日期的方式不同,我只有毫秒精度问题。

What type has the SQL table column for your date? Can it store seconds?

您的日期的SQL表列是什么类型的?可以存储秒数吗?

#2


As i was using a smalldatetime data field initally i forgot to update my data access layer (linq) after i changed it to datetime. Updating the linq data context has solved my problem. Thanks all.

因为我最初使用的是smalldatetime数据字段,所以在将其更改为datetime之后忘记更新我的数据访问层(linq)。更新linq数据上下文已经解决了我的问题。谢谢大家。