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 part 2

Status
Not open for further replies.

msalvador

Programmer
Nov 13, 2001
33
0
0
IT
Hi,
insert part 1

-----------------------------------------------------------
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', ????,????)


gana78 (Programmer) Feb 7, 2002
-- 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

-----------------------------------------------------------
my field must be a datetime, not a varchar.
With the microsoft console i can store only the time 1:00:00 PM f.e.
what's the query
 

There is no way to store just the time part in a datetime column. A datetime column is essentially a decimal number. The whole number portion is the date and decimal portion is the time. Store your time. The whole number portion will be zero (0). Then select a time format (style 108) to display the time. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top