469,336 Members | 5,552 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Insert Time into SmallDateTime Column?

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
Jul 19 '05 #1
4 12715
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.)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"James Goodman" <j a m e s@norton-associates.co.u k> wrote in message
news:bu**********@hercules.btinternet.com...
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

Jul 19 '05 #2
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
Jul 19 '05 #3
sql = "INSERT table_name(smalldatetime_column_name) VALUES('20040121
09:35')"
connObject.execute sql,,129

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"James Goodman" <j a m e s@norton-associates.co.u k> wrote in message
news:bu**********@sparta.btinternet.com...
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

Jul 19 '05 #4
Perfect...

Thanks :)

--
Cheers,

James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by teddysnips | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.