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 2005 Forums
 Transact-SQL (2005)
 how best to record time?

Author  Topic 

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2009-01-06 : 14:33:10
Hi

Quite simply, I'd like to know how best to record a time value (10:30pm) where I'm not concerned about the date? What Data Type should I use in MS SQL?

Many thanks
Richard

Richard Law

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-06 : 14:34:38
It depends what you intend to do with the data. If you ever need to perform time calculations, then you should use datetime with perhaps a date of 01-01-1901. If you never need to perform any calculations on it or formatting of the time, then you could just use varchar.

So how will the data be used?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2009-01-06 : 15:10:20
Hi, thanks. I will want to preform calculations. I'll need a timeStart and a timeFinish.

I'll also only by interested in the 00:00 (h + m) not the seconds. So if I'm to use a dateTime, how would I then create a view with the two times in 00:00 and then a thrid column with the duration between the two?

Thanks for any help
Richard
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-01-06 : 15:29:10
This forum link may help you as well. It appears someone else asked a similar question.

I do not know if it was written specifically for any particular flavor of sql. I think in sql2008 this can be done easier though.

[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74746[/url]

r&r
Go to Top of Page
   

- Advertisement -