2011-01-28 125 views
0

当我尝试在SQL Server查询编辑此查询INSERT INTO日期查询给我错误的日期的SQL Server

INSERT INTO table (postdate) Values (07/09/2010) 

INSERT INTO table (postdate) Values (cast (07/09/2010 as datetime) 

它插入此1/1/1900 12:00:00 AM

为什么我这里错过了吗?

+0

http://www.sqlusa.com/bestpractices/datetimeversion/ – 2011-01-28 18:48:24

回答

3
 INSERT INTO table (postdate) Values ('2010-09-07') 
2

07/09/2010 = 7除以9除以2010以整数运算

这当然给零,这是01 Jan 1900 00:00:00.000

使用SQL Server “安全” 的ISO(YYYYMMDD)+定界符

INSERT INTO table (postdate) Values ('20100907')