views:

48

answers:

2

I've 2 columns called record time and unload time which is in time format AM/PM and I require a new column called total time where I need to find difference between unload time and record time...

for example here is my table

record time  unload time
11:37:05 PM  11:39:09 PM
11:44:56 PM  1:7:23 AM

For this I require a new column which finds the difference between these 2 columns.

Cab anyone suggest a query for this please?

+1  A: 

why you cant go with datediff system function in SQL SERVER

select  datediff(mi,'11:37:05 PM','11:39:09 PM')

mi/n is for minute

anishmarokey
A: 

If you're doing timespan calculations within one 24 hour period, anishmarokey's response is correct. However, I'd add the date to the time field as well, if you're going to have cases where the load and unload might occur over midnight between two or more days.

Randolph Potter
DATEDIFF works fine betwenn the days. For instance, datediff(mi, '2009-09-01 12:00:00', '2009-09-07 12:00:00') gives 8640.
VladV
I wasn't arguing that at all, Vlad. OP said that the fields are time format. No mention of date format. Please explain downvote.
Randolph Potter