Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert only time

Status
Not open for further replies.

msalvador

Programmer
Nov 13, 2001
33
0
0
IT
Hi, I've a table with a field datetime.
I'd like to write into only the time.
insert into CO_Period_Type (DE_Description, TS_Start_Time, TS_End_Time) values ('7777', ????,????)
 
-- code starts here
use pubs
go

create table tablename (dt1 datetime, dt2 varchar(8))
go

declare @abc varchar(8)
set @abc = convert(varchar(8), getdate(), 108)
insert into tablename values (@abc, @abc)

select *
from tablename
--code ends here

Since you have defined the column as "DATETIME" the sql server will add the default date of 1900-01-01.

If you want to avoid it, define the column as VARCHAR(8)

Hope this helps :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top