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.
| Author |
Topic |
|
richardlaw
Yak Posting Veteran
68 Posts |
Posted - 2009-01-13 : 14:34:09
|
| HiI'm using a simple table with two values (timeFrom and timeTo) each as dateTime. I'd like to create a view that works out just the time difference between the two, for example 1.5 would be 1 and 1/2 hours difference. I'm not at all interested in the date values.Many thanksRichardRichard Law |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-01-13 : 14:55:21
|
quote: Originally posted by richardlaw HiI'm using a simple table with two values (timeFrom and timeTo) each as dateTime. I'd like to create a view that works out just the time difference between the two, for example 1.5 would be 1 and 1/2 hours difference. I'm not at all interested in the date values.Many thanksRichardRichard Law
as long as your record is of datetime data type, it will have the date component. what if the time difference is 27.5 hours, what would you want to display here? |
 |
|
|
richardlaw
Yak Posting Veteran
68 Posts |
Posted - 2009-01-13 : 14:58:57
|
| The time difference will only ever be between 30 minutes and 2.5 hours. Is there a way to work this out discarding the date info?ThanksRichard |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-01-13 : 15:28:28
|
| DECLARE @DATE1 DATETIMEDECLARE @DATE2 DATETIMESET @DATE1 = '2009-01-13 15:30:00'SET @DATE2 = '2009-01-13 13:00:00'SELECT DATEDIFF(N, @DATE2, @DATE1) MINUTES |
 |
|
|
|
|
|