开发者

SQL Query doing strange thing

If I run this query on SQL Server Express 2008 :

Insert NoteBook (Date, Note) Values ('11/04/2011 11:02:46', 'test')
开发者_JS百科

It stored the date as 04/11/2011

How can I prevent this?


Use the ISO-8601 format: YYYYMMDD (or YYYY-MM-DDTHH:MM:SS) - it works always, regardless of your SQL Server language and locale settings.

INSERT INTO dbo.NoteBook(Date, Note) 
VALUES('2011-04-11T11:02:46', 'test')

The date in SQL Server is NOT stored in any particular string-oriented format - a date is a date is a date, regardless of what you see.

You see a string representation of the date - but again: it's NOT stored that way - and thus you cannot "prevent" it from being stored that way...

Check your language settings in SQL Server:

SELECT @@LANGUAGE

What language do you have?? The language defines the default format in which dates are shown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜