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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How I can use insert into statement to insert datetime to table?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-26 : 09:51:25
Chantana writes "How I can use insert into statement to insert datetime to table?
Ex.
Table1 it is a table that has 1 Fields and it data type is smalldatetime
when I use insert into command ,I use
insert into TableName (FieldsName)
values ( 5/5/2002)
ps. 5/5/2002 is m/d/yyyy
when I run test this command on Query analyser on SQL Server it work no error .But when I brows to see the data in the table .The value of my date it become 1/1/1900 .I want to know why ?
Please answer my question
thanks !"

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-06-26 : 10:10:33
try using a convert function in the insert... Its just having a conversion problem. is this sql 7.0 or 2k? or other?

convert(smalldatetime,'5/5/2002')

-----------------------
Take my advice, I dare ya
Go to Top of Page

DavidD
Yak Posting Veteran

73 Posts

Posted - 2002-06-26 : 21:47:37
All you need are single quotes around the date
ie:
insert into tablename(datefield)
values ('5/5/2002')


Go to Top of Page

dataphile
Yak Posting Veteran

71 Posts

Posted - 2002-06-28 : 05:57:22
Your regional settings might stuff things up as well.

Rather use values('2002/05/05') which SQL seem to always understand ,
or better yet values('05 may 2002').

Go to Top of Page
   

- Advertisement -