Results 1 to 3 of 3

Thread: hours cal

  1. #1
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    8

    Red face Unanswered: hours cal

    Dear frinends

    I need to substract the hours. I need to calculate the hours worked after 6:00pm.

    input is strat time like 30:june:03:30 PM until 8:00pm in night

    I need to calculate the hours he worked after 6:00pm.

    please help
    elam

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    something like this?

    Code:
    declare @d datetime
    set @d = dateadd(hh,-12,getdate())
    select @d
         , dateadd(hh,18,convert(varchar(10),@d,120))
         , datediff(hh,dateadd(hh,18,convert(varchar(10),@d,120)),@d)
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    This calculates minutes worked after 6 pm. You could change it to calculate hours if you don't want the extra accuracy.

    select (datediff(mi, convert(varchar(10), @d, 120) + ' 18:00', @d) + abs(datediff(mi, convert(varchar(10), @d, 120) + ' 18:00', @d)))/2

    The absolute value conversion is used to return 0 instead of negative hours.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •