Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 datetime error

Author  Topic 

renu
Starting Member

47 Posts

Posted - 2007-10-15 : 01:38:03
declare @table table(c1 int,c2 datetime)


insert into @table (c1,c2) values(1,'14/01/2007')

when i execute this the following error appears:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-15 : 01:41:37
Always use ISO (yyyymmdd) format while inserting datetime data manually:

declare @table table(c1 int,c2 datetime)
insert into @table (c1,c2) values(1,'20070114')


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

renu
Starting Member

47 Posts

Posted - 2007-10-15 : 02:01:45
ya, but when i put c2 value as '13/01/2007'

in that case my value gets inserted.
but from 14 and above date my values r not getting inserted

it throw the above error.

declare @table table(c1 int,c2 datetime)


insert into @table (c1,c2) values(1,'14/01/2007')
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-15 : 02:21:17
so why exactly aren't you listening to harsh's advice??

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-15 : 02:32:32
declare @table table(c1 int,c2 datetime)

SET DATEFORMAT DMY
insert into @table (c1,c2) values(1,'14/01/2007')

will also work.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-15 : 03:06:57
quote:
Originally posted by renu

ya, but when i put c2 value as '13/01/2007'

in that case my value gets inserted.


How?
What is the dateformat of the server?
Run this and see

DBCC Useroptions


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -