Algorithm for how many hours in Excel to find two intervals

Source: Internet
Author: User

Today, I received a letter from a student asking for an algorithm to calculate the number of hours between two points, along with a request: 30 minutes per 0.5 hours, such as 25 minutes 0, 45 minutes can be counted 0.5 hours. This application is particularly useful in calculating overtime work and is now shared as follows:

Suppose column A has the start time, column B is the end time, and the number of overtime hours in column C.

Start time End time Hours of overtime
8:00 16:00 8
8:00 15:30 7.5
16:00 0:00 8
16:00 23:30 7.5
0:00 8:00 8
0:00 7:30 7.5
19:30 7:30 12
19:30 7:00 11.5
16:00 16:25 0
16:00 16:30 0.5
16:00 16:45 0.5

The specific formula is as follows: =rounddown (ROUND (B2-A2) *24*60,0)/30,0)/2

Explanation: Subtract time from time, the result is a decimal in days, so multiply it by 24 hours and multiply by 60, convert to minutes, and, in 30 minutes, perform an unconditional position operation RoundDown (), and find a few 30 minutes, and then divide by 2 to convert to hours. Because of the precision of the decimal point, the above method to find the data may be less than 0.5 hours, so add a rounding function round (), to ensure that the decimal part of the error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.