472,146 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 12799
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
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.