简体   繁体   English

C#将DateTime转换为Sql Server 2005格式

[英]C# Convert DateTime To Sql Server 2005 Format

How Can I Turn This DateTime value into something that Sql Server 2005 won't shout at me for. 如何将该DateTime值转换为Sql Server 2005不会对我大喊大叫的东西。

2007-12-01T00:00:00+00:00 2007-12-01T00:00:00 + 00:00

(All I care about is the date, NOT the time). (我只关心日期,而不是时间)。

I get this error when I tried to pass this argument to my stored procedure as a DateTime variable (Both the C# object and the Sql Server object are DateTime variables and need to be) : "Conversion failed when converting datetime from character string." 当我尝试将此参数作为DateTime变量传递给我的存储过程时,出现此错误(C#对象和Sql Server对象都是DateTime变量,需要这样):“从字符串转换datetime时转换失败。”

sql服务器将接受的一种转换日期的好方法是以下格式:yyyymmdd,例如20071201。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM