barkarlo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barkarlo
    New Member
    • Nov 2006
    • 59

    #1

    barkarlo

    what do I have to do,so the function returns the correct result when the end of the worktime passes midnight?
    Public Function HoursAndMinutes (interval as variant) as string
    dim totalminutes as long, totalseconds as long
    dim hours as long, minutes as long, seconds as long
    if isnull(interval )= true then exit function
    hours = Int(CSng(interv al*24))
    totalminutes = Int(CSng(interv al*1440))
    minutes = totalminutes mod 60
    totalseconds =Int(CSng(inter val*86400))
    seconds = totalseconds mod 60

    if seconds>30 then minutes = minutes+1
    if minutes>59 then hours = hours+1:minutes =0
    HoursAndMinutes = hours & ":" & format(minutes, "00")
    End function

    for an example starttime endtime function return totalwork
    22:30 02:30 -20:00
    I want to see 04:00

    Thanks for help
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    One fairly simple approach is just to add a day if the end time is earlier than the start time. Like...
    Total = End - Start - 86400 * (Start > End)
    This is just a rough version straight off the top of my head. (It works on the assumptions that True equates to -1, and you are working in seconds).

    Comment

    Working...