Author: Oscar Cronquist Article last updated on October 24, 2018

The formula in cell D5 calculates the number of complete hours between the time entries in cell B5 and C5.

Formula in cell D5:

=HOUR(ABS(C5-B5))

Note that this formula works only with time entries, not date and time entries. It doesn't matter if the start time is past the end time, the formula will regardless return a positive hour value.

### Explaining formula in cell D5

#### Step 1 - Subtract time entries

C5-B5

becomes

6:00:00 AM -Â 12:00:00 AM

Time entries in excel are actually a decimal value between 0 (zero) and 1. One hour is 1/24, six hours is 6/24 and so on.

0.25 - 0 equals 0.25

#### Step 2 - Remove sign

The ABS function removes the minus sign if it exists, the HOUR function can't calculate negative values.

ABS(C5-B5)

becomes

ABS(0.25) and returns 0.25.

#### Step 3 - Convert decimal to hour(s)

The HOUR function calculates hours based on a decimal value.

HOUR(ABS(C5-B5))

becomes

HOUR(0.25)

and returns 6.

The image above demonstrates a formula the returns negative hours if the start time is later than the end time.

Formula in cell D5:

=HOUR(ABS(C5-B5))*IF(C5<B5,-1,1)

### Explaining formula in cell D5

This part of the formula HOUR(ABS(C5-B5)) is explained above.

#### Step 1 - Calculate if end date is smaller than the start date

C5<B5

becomes

0.25<0

and returns FALSE.

#### Step 2 - Return -1 if TRUE and 1 if FALSE

IF(C5<B5,-1,1)

becomes

IF(0.25<0,-1,1)

becomes

IF(FALSE,-1,1) and returns 1.

#### Step 3 - Multiply with result

HOUR(ABS(C5-B5))*IF(C5<B5,-1,1)

becomes

6*IF(C5<B5,-1,1)

becomes

6*1 and returns 6 in cell D5.

The picture above shows a formula that calculates complete hours between date and time entries.

Formula in cell D5:

=TEXT(ABS(C5-B5),"[h]")

If you want negative hours then remove the ABS function:

=TEXT(C5-B5,"[h]")

The TEXT function formats the result of C5-B5 into complete hours.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.get-digital-help.com/2018/10/24/count-complete-hours-between-two-times/", "fetch_time": 1553516608000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2019-13/segments/1552912203947.59/warc/CC-MAIN-20190325112917-20190325134917-00132.warc.gz", "warc_record_offset": 754149260, "warc_record_length": 33476, "token_count": 579, "char_count": 1944, "score": 4.125, "int_score": 4, "crawl": "CC-MAIN-2019-13", "snapshot_type": "longest", "language": "en", "language_score": 0.8207654356956482, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00021-of-00064.parquet"}