Sub topic 5
Time of day as a fraction of a day
This chapter assumes you can enter formulas, use cell references such as A2, and apply a number format to a cell. It also assumes you know that Excel stores a date as a whole-number serial number, the count of days since the start of the date system.
The model: the decimal part is the time
A serial number can have a decimal part. The whole part says which day it is. The decimal part says how far through that day you are, as a fraction of 24 hours.
- 0.0 is midnight at the start of the day.
- 0.25 is 6:00 AM, one quarter of the day.
- 0.5 is noon.
- 0.75 is 6:00 PM.
So 45000.5 is noon on 15 March 2023, and 45000.75 is 6:00 PM on the same day. Excel does not keep separate "date" and "time" values. It keeps one number, and the cell format decides how much of it you see.
Seeing the fraction
Enter this formula in a cell formatted as General:
=DATE(2023,3,15)+0.75The cell shows 45000.75. Apply a custom format such as d mmm yyyy h:mm AM/PM and it shows 15 Mar 2023 6:00 PM. The stored value is the same in both cases. Only the display changes.
Building a time from hours, minutes, and seconds
The TIME function turns hours, minutes, and seconds into a fraction of a day:
=TIME(18,0,0)With General formatting this shows 0.75. You can add it to a date to build a full date and time:
=DATE(2023,3,15)+TIME(9,30,0)This returns 45000.3958333, which displays as 9:30 AM on 15 March 2023 when formatted as a date and time.
The arithmetic behind it is simple. One hour is 1/24 of a day, so 9 hours and 30 minutes is 9.5/24, which is about 0.3958.
Date arithmetic with times
Because times are fractions, subtraction still works. Suppose A2 holds a start time and B2 holds an end time on the same day or a later day:
=B2-A2The result is the elapsed time as a fraction of a day. To convert it to hours, multiply by 24:
=(B2-A2)*24For example, 8:00 AM to 5:30 PM is 0.7083 - 0.3333 = 0.375 days, which is 9.5 hours.
Other units follow the same pattern. Multiply by 2460 for minutes, or by 2460*60 for seconds.
Extracting the date or the time
To get only the date, drop the fraction with INT:
=INT(A2)To get only the time, keep the fraction:
=A2-INT(A2)Format the second result as a time, or it displays as a small decimal.
Common errors
- Hash signs (#####). A negative time cannot be displayed in the 1900 date system. This happens when an end time is earlier than a start time, for example a shift that crosses midnight. Add 1 when the end is earlier:
=B2-A2+(B2<A2). - A time that looks wrong. Check the cell format. A value such as 0.75 under General is not broken. It is a time that has not been formatted.
- A time total that stops at 24 hours. The format
h:mmwraps around after 24 hours. Use[h]:mmto show cumulative hours. - Dates that do not match. A date with a hidden time part, such as one from NOW, is not equal to the same date entered without a time. Use INT to remove the fraction before comparing.
Exercise
Cell A2 holds 45000.25 and is formatted as General. What date and time does it represent, and what formula gives the number of hours between A2 and 45001.5?
Show answer
It is 15 March 2023 at 6:00 AM, because 0.25 of a day is 6 hours. The elapsed time is 45001.5 - 45000.25 = 1.25 days, so the formula =(45001.5-A2)*24 returns 30 hours.
Exercise
A night shift starts at 10:00 PM in A2 and ends at 6:00 AM in B2, with both cells holding times only. Why does =B2-A2 fail, and how do you fix it?
Show answer
B2 (0.25) is smaller than A2 (about 0.9167), so the result is negative, and a negative time shows as #####. Use =B2-A2+(B2<A2) to add one day when the end is earlier. That gives 0.3333 days, or 8 hours when multiplied by 24.