How can i store only time in sql Server 2008

Posted by See29ram under ASP.NET on 3/22/2012 | Points: 10 | Views : 6870 | Status : [Member] | Replies : 4
I have fields are Date and Time,in that i need to store only time from DateTime field How can i do?




Responses

Posted by: Gopinath on: 3/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
1. SQL Server 2008 adds a Time data type, so you might want to consider that.
2. You can use SQL 2005's DateTime type and combine it with the CONVERT function to extract just the HH:MM:SS.MMM

SELECT CONVERT(VARCHAR(12), GETDATE(), 114) AS [HH:MI:SS(24H)]
The four new data types for storing dates and times in SQL Server 2008 are

* Date
* Time
* DateTime2
* DateTimeoffset


C.Gopinath

See29ram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/22/2012 [Member] Bronze | Points: 25

Up
0
Down
Yes there is a time datatype in sql 2008, you can use that.

Thanks,
Rajni Shekhar

See29ram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Leo.Zhang on: 3/22/2012 [Member] Starter | Points: 25

Up
0
Down
there is a type named "time" in sql server 2008, you can use it.

See29ram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/22/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Rajani,
Try this:

CREATE TABLE dbo.timeManage

(
col_time time(7) NULL
)

INSERT INTO dbo.timeManage(col_time)
VALUES (GETDATE())
GO

select * from timeManage


Thanks,
Sanjay

See29ram, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response