RSS Forums RSS
Please support our ColdFusion advertiser: Programming Forums

finding duration worked between time ranges from login and logout time

Join Date: Mar 2007
Posts: 28
Reputation: cfAllie is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cfAllie cfAllie is offline Offline
Light Poster

Re: finding duration worked between time ranges from login and logout time

  #4  
Mar 30th, 2007
Hi Ramesh,

This example might be more complex than what you need, but it should give you a starting point. Caveat - This example only counts the time that fall within @start and @end period. So for example if an employee started work at 11/1/06 6:30AM, and you entered a @start date of 11/1/06 7:30 am, the hour between 6:30AM and 7:30AM would not be counted.

--- counts ONLY the time worked between @start and @end 
SELECT    e.emp_id,
    SUM 
    ( 
        DATEDIFF 
        (n,
        CASE WHEN login_time < @start THEN @start ELSE login_time END,
        CASE WHEN logout_time > @end THEN @end ELSE logout_time END
        ) 
    ) 
    AS TotalTimeWithinDateRange
FROM    LoginTable lt 
    INNER JOIN Store s ON lt.store_id = s.store_id
    INNER JOIN Employee e ON lt.emp_id = e.emp_id
WHERE    s.store_id = @store_id AND 
    (
        (lt.login_time BETWEEN @start AND @end) OR
        (lt.logout_time BETWEEN @start AND @end) OR
        (lt.login_time <= @start and logout_time >= @end)
    )
GROUP BY e.emp_id
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC