469,927 Members | 1,848 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

calculating total time using datediff()

hi

i have i table called Description which has details about StartTime , EndTime and ScheduleDate of the various Transaction occuring daily.I want to fetch total time spend on a particular transaction which can occur on any day of week.Eg:

A transaction occured on 5th jan from 2pm to 3pm and
on 6th jan 1pm to 3pm
so total time spent is 1+2= 3 hrs.
Can this be done with a query ? or i hav to do some changes in my code.?



Regards
Jul 30 '07 #1
1 9158
hi

i have i table called Description which has details about StartTime , EndTime and ScheduleDate of the various Transaction occuring daily.I want to fetch total time spend on a particular transaction which can occur on any day of week.Eg:

A transaction occured on 5th jan from 2pm to 3pm and
on 6th jan 1pm to 3pm
so total time spent is 1+2= 3 hrs.
Can this be done with a query ? or i hav to do some changes in my code.?



Regards
This transaction is the same one over and over and you need a running total?

Expand|Select|Wrap|Line Numbers
  1. Select sum(Datediff(hour,StartTime, EndTime))
  2. Where TransactionID = 12345
Or if you want to list the totals for all the transactions.

Expand|Select|Wrap|Line Numbers
  1. Select TransactionID, sum(Datediff(hour,StartTime, EndTime))
  2. Group By TransactionID
These will do it in hours, if you want more precision you use minutes or seconds and then do the math to get your display right.
Aug 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Phil Sandler | last post: by
1 post views Thread by Shaun Thornburgh | last post: by
4 posts views Thread by luscus | last post: by
3 posts views Thread by luscus | last post: by
8 posts views Thread by =?Utf-8?B?QWw=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.