SeanB, you're not giving us much to work with. You haven't told us in what context you are trying to do this (a stored procedure, ADO from VB or IIS, Query Analyzer, ODBC, etc).
Generally, this:
[tt]declare @MyDateVar datetime
set @MyDateVar = '07/26/2001' [/tt]
will set the time portion to 00:00, or 12:00 AM. Robert Bradley Support operation moo!
Visit the OpCow page
SeanB, again I'm just guessing, but do you mean that you only want to store the time without the date? Is this what you mean by the "1/1/1900 problem"? If so, in SQL Server a datetime or smalldatetime type value always has a date component; there's no way around that. You could use another data type, or you could choose to ignore the date portion of the value. You can even use DatePart() to retrieve only portions of the value. Robert Bradley Support operation moo!
Visit the OpCow page
You can also use the Convert function to return only the time portion of the field.
Select convert(char(8), datetimecolumn, 108) As TimeOnly
From tbl
Note 1: 108 represents a datetime time of hh:mm:ss.
Note 2: Don't get hung up on the way SQL Server stores dates and times. The storage format is fixed. Learn to use the datetime functions and Convert to display the data the way you want and you'll eliminate a lot of frustration and headaches associated with dates and times in SQL Server. Terry Broadbent
"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.