question

sqlnewb avatar image
sqlnewb asked

Datetime Insert Error

I am getting these errors when trying to insert datetime value into my table SET IDENTITY_INSERT table1 ON CREATE TABLE table1 ( id int PRIMARY KEY IDENTITY, submitted datetime NOT NULL) INSERT INTO table1 (id, submitted) Values (8, '2011-07-06 12:00:06') I get this error: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. If i try INSERT INTO table1 (id, submitted) Values (8, 2011-07-06 12:00:06) I get this error: Incorrect syntax near '12'.
sql-server-2008t-sqldatetime
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
You will need to put the date value in quotes ' like INSERT INTO table1 (id, submitted) Values (8, '2011-07-06 12:00:06') assuming the date string can be unambiguously converted to a date in your locale/regional settings
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sqlnewb avatar image sqlnewb commented ·
I've tried that I get the error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
That's why I said make sure it can be a date :) try values(8, '6 July 2011 12:00:06')
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.