在表SqlServer 2008中插入日期时出现问题 [英] Problem while Inserting date in table SqlServer 2008

查看:107
本文介绍了在表SqlServer 2008中插入日期时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试插入日期'05 / 01/2015'(mm / dd / yyyy)但它保存得像

'1901-02-08 00:00:00.000'



如何以正确的方式插入..?

Hi,

I'm trying to insert a date '05/01/2015' (mm/dd/yyyy) But it saved like
' 1901-02-08 00:00:00.000 '

How can i insert it in correct way .. ?

推荐答案

INSERT INTO MyTable (MyDate) Values (GetDate())





OR





OR

INSERT INTO MyTable (MyDate) Values (Convert(DateTime,'20150501',112))







试试这个




try this


简单:以ISO格式传递:yyyy-MM- dd so 2015-05-01

或通过参数化查询将其作为DateTime对象传递。

将日期作为字符串传递总是涉及SQL的一部分猜测 ,但ISO格式应该始终是正确的。
Simple: pass it in ISO format: yyyy-MM-dd so 2015-05-01
or pass it as a DateTime object via a parametrized query.
Passing dates as strings always involves some "guesswork" on teh part of SQL, but ISO format should always be correct.


你可以使用转换功能:



you can do it with convert function:

select CONVERT(datetime, '05/01/2015', 110)





见这里:http://msdn.microsoft.com/en-us/library/ms187928.aspx [ ^ ]


这篇关于在表SqlServer 2008中插入日期时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆