How can I calc a percentage of an hour?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndyB2
    New Member
    • Dec 2011
    • 49

    How can I calc a percentage of an hour?

    Access 2010:

    I need to calc the difference between two times then calc a percentage of an hour?

    Code:
    !StartTimeStamp1 = StartTime
    !EndTimeStamp1 = MDrs("TimeStamp1")
    !Total_time = MDrs("TimeStamp1") - StartTime
    First problem, the above code is giving the following result, adding 12 hours when the difference is less than one hour. See attachment.

    [imgnothumb]http://bytes.com/attachments/attachment/6233d1331908530/time-example.jpg[/imgnothumb]

    Second problem I cannot find a good example to calc a percentage of an hour. i.e. if the above field "Total_time " = 29:51 then I want to calc 29:51 / 60:00 = .4975

    Hope I explained my problem correctly
    Attached Files
    Last edited by NeoPa; Mar 17 '12, 11:03 PM. Reason: Made pic viewable.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The results are correct. 12:29:51 AM is 29:51 minutes from time 0 which is 12:00 AM, or in 24 hour format, 00:00:00. In 24 hour format, it's 00:29:51. In 12 hour format, it's 12:29:51. There is also a date component that you don't see.

    You seem to think that there is a time only data type. There is no such data type. They are all date AND time data, even if you don't display one or the other.

    To calculate a percentage of the hour, Get the number of minutes, multiply by 60, add the number of seconds, then divide by 3600. That's if you want it down to the precision of a second. If you just care about the minutes, take the number of minutes and divide by 60. Use the DATEPART function to grab a section of a date time field.

    Comment

    Working...