Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 placing military time only in datetime field

Author  Topic 

steelkilt
Constraint Violating Yak Guru

255 Posts

Posted - 2003-11-13 : 08:58:36
Hi. I'd like to write only the time portion of a datetime field to my table when I'm both inserting and updating the records.

I am able to use

convert(char(8),timecheck,114)
as military_time

with a select statement to shave off the date part when querying a table, but, again, I'd like to remove the date part altogether before the record gets written to the table, if possible, via my sprocs. In the sproc, I'm first converting a varchar data type (passed from a web form) to datetime. I'd then like to shave off the date piece, but don't know at which point in the sproc the shaving would occur:

@TimeFound varchar (40),

AS

DECLARE @TimeFound_converted datetime

SET @TimeFound_converted=CONVERT(datetime, @TimeFound)



INSERT INTO TABLE

(TimeFound)


VALUES


(@TimeFound_converted)


thx.

steelkilt
Constraint Violating Yak Guru

255 Posts

Posted - 2003-11-13 : 10:01:35
OK, I'm using select CONVERT as above to display only military time in the web form which is the main requirement. upon further reflection, if I were to shave off date and write only the time portion to the field, this would require a data type conversion to varchar or some such, removing the datetime data type and all functionality that goes with it, no?

thx.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-11-13 : 10:15:03
SELECT RIGHT(CONVERT(varchar(19),GetDate(),120),8) AS Miltary_Time


Brett

8-)
Go to Top of Page
   

- Advertisement -