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 2005 Forums
 Transact-SQL (2005)
 date insert fails

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2007-10-03 : 03:29:25
Hi

I have a smalldatetime field and try to insert a date using this code...

INSERT INTO tbl_P_Comments
(DateMade, PID, AID)
VALUES
(28/9/2007,35,32)

But when I do that the date inserted is 1900-01-01 00:00:00

Why is that? Am I doing something wrong...

Regards

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-03 : 03:51:42
what you are specifying is 28 divide by 9 divide by 2007 = 0

INSERT INTO tbl_P_Comments
(DateMade, PID, AID)
VALUES
('20070928',35,32)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-03 : 04:14:47
1 date values should be expressed within single quotes
2 better to use YYYYMMDD HH:MM:SS format as suggested

Madhivanan

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

magmo
Aged Yak Warrior

558 Posts

Posted - 2007-10-03 : 04:31:10
Hi

Allrighty, got it working now, Thanks!

Regards
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-03 : 04:38:32
quote:
Originally posted by magmo

Hi

Allrighty, got it working now, Thanks!

Regards


Also make sure you use proper DATETIME datatype to store dates

Madhivanan

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

magmo
Aged Yak Warrior

558 Posts

Posted - 2007-10-03 : 05:30:40
I use smalldatetime
Go to Top of Page
   

- Advertisement -