views:

372

answers:

4

I have the field:

APP_DATE (smalldatetime)

I'm doing this query:

INSERT INTO table (TYPE, CODE, APP_DATE, DATE) VALUES ('APP', '123', '02/10/2010 12.30', GETDATE())

It fails:

Msg 296, Level 16, State 3, Line 1
Conversion from datatype char to smalldatetime generated a value not between the interval of valid values.
Instruction has been interrupted.

(0 row(s) affected)

What am I doing wrong? It appears to me as the correct format for the field..

Thank you for your time.

EDIT: SQL Server 2000

+1  A: 

The date time format isn't correct; the year should be 4 digit (otherwise it is ambiguous) and the time separator should be a colon.

2003/01/22 22:31 will work. see this article.

Richard Harrison
+1  A: 

Just use : in your time instead of .. Then it will insert fine.

Graham Clark
Still doesn't work:'02/19/2010 16:28' <- Same error
0plus1
@0plus1: works just fine for me.....
marc_s
Ah, I have SQL Server 2005. Maybe that's the problem. Try changing the format of the date, maybe '2010-19-02 16:28' ? Or perhaps you've got the wrong locale settings, does it think 19 is the month?
Graham Clark
A: 

If you do not need the time element in the field SQL Server will default it to 00:00:00 for you if you just send in '02/10/2010' If you need the time element then your format for the time is wrong in your example and it should be something like this - '02/10/2010 12:31:00'

VBCSharp
+2  A: 

Can you try to use the ISO-8601 date format (YYYYMMDD HH:MM:SS) - this will work always on SQL Server - regardless of your regional and locale settings:

INSERT INTO table (TYPE, CODE, APP_DATE, DATE) 
VALUES ('APP', '123', '20100210 12:30:00', GETDATE())
marc_s