Groups | Blog | Home
all groups > sql server (alternate) > february 2004 >

sql server (alternate) : insert time


santoshamb NO[at]SPAM yahoo.com
2/12/2004 10:40:34 PM
I have the table:

Create Table ServiceSched(
[key] primary key NOT NULL,
[starttime] datetime NOT NULL,
[endtime] datetime NOT NULL)

(sql might not be perfect)

when I enter records manually using enterprise manager, I type
something like "8:00" into the starttime field, and E.M. expands the
time to "8:00:00 AM".

if I use a sproc to enter times

alter proc addSchedule(
@inStartTime datetime,
@inEndTime datetime)

as

INSERT INTO ServiceSched([StartTime],[EndTime])
VALUES (@inStartTime,@inEndTime)

return

execute addSchedule('8:00', '9:00')

and then I look in enterprise manager, it has expaned these to
'1/1/1900 8:00:00 AM' and '1/1/1900 9:00:00 AM'

why is this? does it make a difference? am I inserting times wrong via
a stored procedure?

thanks for the help,

sql NO[at]SPAM hayes.ch
2/13/2004 2:17:28 AM
[quoted text, click to view]

MSSQL always stores date and time together, and if you don't specify a
date, it will default to 1/1/1900, which is what you are seeing. I
don't know why Enterprise Manager would display data inconsistently,
so you may want to use Query Analyzer instead, as it's a more
'direct' way to view the data:

select StartTime, EndTime
from ServiceSched

John Bell
2/13/2004 9:54:49 AM
Hi

As the datetime datatype suggests there is no time only data type in SQL
Server. When you don't specify the date it will use a default. Use the
CONVERT function to format to the date/time into a string See Books online:
mk:@MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Books\tsq
lref.chm::/ts_ca-co_2f3o.htm

Alternatively you may want to store your time as a different data type e.g.
Number of minutes

John

[quoted text, click to view]

AddThis Social Bookmark Button