Insert Time into SmallDateTime Column?

J

James Goodman

I have an asp page which the user enters a time(e.g. 12:21). I need to
insert this time into a SQL Server DB, which has a smalldatetime column.

I have tried everything I can think of (such as CDate, TimeValue,
FormatDateTime etc) to convert the time string, into a valid time. However,
the insert always try to insert a datetime datatype (e.g. 12/12/1899
12:21:00).

I am trying to process the insert through ado, eg:

objRS.AddNew
objRS("Field1") = strText
objRS("DateField") = dteValue
objRS.Update

Any suggestions as to how I can solve this?

--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
A

Aaron Bertrand [MVP]

SQL Server will always add a date component. If the date is always
12/12/1899, can't you just ignore the date part???
http://www.aspfaq.com/2206

(Also, SQL Server would put 1900-01-01 as the date, so I think that's
VBScript adding the date for you. And finally, use an INSERT statement
instead of rs.AddNew.)
 
J

James Goodman

My problem is not that I cant ignore the date part of the time inserted.

I simply cannot insert anything into a smalldatetime field from asp.

Can you give me, or point me in the direction of an example for using an
insert command instead of objRS.AddNew etc?



--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
A

Aaron Bertrand - MVP

sql = "INSERT table_name(smalldatetime_column_name) VALUES('20040121
09:35')"
connObject.execute sql,,129
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top