ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Logic
  3. IF Time Between Two Times in Excel: Shifts and Cutoffs

IF Time Between Two Times in Excel: Shifts and Cutoffs

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

To test if a time is between two times, combine IF and AND: =IF(AND(B2>=TIME(9,0,0),B2<TIME(17,0,0)),"In hours","Out of hours"). For a window that crosses midnight, such as 22:00 to 6:00, use OR instead of AND. If the cell holds a date and time, test MOD(B2,1) so only the time is compared.

Key takeaways

  • Excel times are fractions of a day, so TIME(9,0,0) is the same as 9/24, or 0.375.
  • For a normal window, use AND: the time must be after the start and before the end.
  • For a window that crosses midnight, use OR: after the start or before the end.
  • Use MOD(B2,1) to strip the date from a timestamp before comparing times.
  • Times stored as text break the comparison. Convert them with VALUE or TIMEVALUE first.
On this page+
  1. How Excel stores times
  2. IF time between two times: the basic formula
  3. Put the start and end times in cells
  4. How to handle a time window that crosses midnight
  5. Times with dates: use MOD to compare only the time
  6. How to count the times between two times
  7. Why your IF time formula gives the wrong answer
  8. Practise it

To check if a time is between two times in Excel, wrap AND inside IF: the time must be at or after the start and before the end. That covers office hours, shift windows and order cutoffs. This guide also shows the two cases that trip people up: windows that cross midnight, such as a 22:00 to 6:00 night shift, and cells that hold text or a full date and time instead of a plain time.

How Excel stores times#

Excel stores a time as a fraction of a day, which is why you can compare times with >= and < like any number. Midnight is 0, 6:00 is 0.25, 9:00 is 0.375 and 17:00 is about 0.708. One hour is 1/24 of a day.

You can write a time inside a formula in three ways, and they all give the same number:

Way to write 9:00ExampleNotes
TIME functionTIME(9,0,0)Clearest: hours, minutes, seconds
Hours divided by 249/24Short; 9:30 is 9.5/24
Text convertedTIMEVALUE("9:00")Reads like a clock

Don't write B2>="9:00". In quotes, 9:00 is text, and Excel compares numbers and text very differently, so the answer is wrong. Dates work on the same idea, with whole numbers for days, as the date basics lesson shows.

The examples below use this clock-in list:

AB
1AgentClock-in
2Maya9:20
3Joel8:55
4Sana12:45
5Felix17:05
6Rosa22:30
7Ken3:10

IF time between two times: the basic formula#

To test a normal window like 9:00 to 17:00, use AND so that both conditions must be true. In C2, type and fill down:

Excel formula
=IF(AND(B2>=TIME(9,0,0),B2<TIME(17,0,0)),"In hours","Out of hours")
  • B2>=TIME(9,0,0) checks the time is 9:00 or later.
  • B2<TIME(17,0,0) checks it is before 17:00.
  • AND returns TRUE only when both are true, and IF turns that into a label.

Maya (9:20) and Sana (12:45) are In hours. Joel (8:55), Felix (17:05), Rosa and Ken are Out of hours.

Decide which end includes the boundary. Here 9:00 counts as in hours (>=) but 17:00 doesn't (<), so a time can never belong to two back-to-back windows. The same pattern works for numbers, as the guide to IF between two numbers shows. The IF function guide and AND function guide cover each function on its own.

Put the start and end times in cells#

Hard-coded times are fine for a quick check, but cells are easier to change. Type 9:00 in F1 and 17:00 in F2, then use:

Excel formula
=IF(AND(B2>=$F$1,B2<$F$2),"In hours","Out of hours")

The $ signs lock F1 and F2 so they stay put when you fill down. Change F2 to 18:00 and every row updates. To combine the time test with other conditions, such as weekday and time, see how IF and AND work together.

How to handle a time window that crosses midnight#

When the window runs past midnight, AND never works, because no time is both after 22:00 and before 6:00. Use OR instead: the time is either late in the evening or early in the morning.

Excel formula
=IF(OR(B2>=TIME(22,0,0),B2<TIME(6,0,0)),"Night","Day")

Rosa (22:30) and Ken (3:10) are Night. Everyone else is Day.

If the window is in cells and could be either kind, one formula handles both. With the start in F1 and the end in F2:

Excel formula
=IF(MOD(B2-$F$1,1)<MOD($F$2-$F$1,1),"Inside","Outside")

MOD with 1 measures how far each time is past the start, wrapping around midnight. If that distance is less than the length of the window, the time is inside. With 22:00 and 6:00 in F1 and F2, Ken's 3:10 is 5 hours 10 minutes past the start, inside an 8-hour window, so he is Inside. With 9:00 and 17:00, the same formula gives the same results as the AND version. For night-shift lengths, see how to calculate time differences that pass midnight, and for a full rota, the shift schedule guide.

Times with dates: use MOD to compare only the time#

A timestamp such as 3 Nov 2026 14:35 is a date number plus a time fraction, so it is always far bigger than TIME(14,0,0). Strip the date first with MOD(A2,1), which keeps only the part after the decimal point.

A typical cutoff rule: orders placed before 14:00 ship the same day.

Excel formula
=IF(MOD(A2,1)<TIME(14,0,0),"Ships today","Ships tomorrow")

An order at 13:59 on any date ships today, and one at 14:00 ships tomorrow. To test the date part instead, such as "before 1 December", see IF with dates.

How to count the times between two times#

To count how many times fall in a window, you don't need a helper column of IF results. COUNTIFS accepts two conditions on the same column, one for each end:

Excel formula
=COUNTIFS(B2:B7,">="&TIME(9,0,0),B2:B7,"<"&TIME(17,0,0))

The result is 2 (Maya and Sana). The & joins each operator to the time, because a function can't sit inside the quotes. For a window that crosses midnight, add two counts instead: =COUNTIFS(B2:B7,">="&TIME(22,0,0))+COUNTIFS(B2:B7,"<"&TIME(6,0,0)) gives 2 (Rosa and Ken).

Why your IF time formula gives the wrong answer#

Most wrong results come from how the times are stored, not from the formula.

  1. Times stored as text. Imported times are often text, which you can spot because they sit on the left of the cell. Excel treats text as larger than any number, so B2>=TIME(9,0,0) is always TRUE and B2<TIME(17,0,0) is always FALSE. Convert with VALUE(B2) or TIMEVALUE(B2), as in the exercise on this page.
  2. The time is in quotes. B2<"17:00" compares against text. Use TIME(17,0,0) or 17/24.
  3. AND for a midnight window. Switch to OR or the MOD version.
  4. A hidden date. If the cell shows 14:35 but the formula bar shows a date as well, use MOD(B2,1).
  5. Tiny rounding gaps. A time calculated by a formula can be a hair below the boundary, such as 16:59:59.999. If exact boundaries matter, compare whole minutes: ROUND(B2*1440,0)<17*60.

Practise it#

Do the exercise on this page: it uses text times, the most common real-world snag. Then build the logic step by step in the IF function lesson and the AND, OR and NOT lesson, where you type each formula and get instant feedback.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

These clock-in times were imported as text. In C2, return In hours if the time in B2 is from 9:00 up to (but not including) 17:00, and Out of hours otherwise. Convert with VALUE and compare with 9/24 and 17/24: type =IF(AND(VALUE(B2)>=9/24,VALUE(B2)<17/24),"In hours","Out of hours").

fx
ABCD
1
Agent
Clock-in
Status
2
Maya
9:20
3
Joel
8:55
4
Sana
12:45
5
Felix
17:05
6
Rosa
22:30
7
Ken
3:10
8
9
10

Tip: VALUE turns "9:20" into a real time. 9/24 is 9:00 and 17/24 is 17:00, because one hour is 1/24 of a day.

Practise this in a lesson

LessonThe IF functionMake a cell show one result or another depending on a condition, like Pass/Fail or Over/Under budget.LessonAND, OR and NOTCheck several conditions at once with AND and OR, flip a result with NOT, and combine them inside IF.LessonHow Excel stores dates: DATE, YEAR, MONTH, DAYLearn why every date is secretly a number, then build dates with DATE and take them apart with YEAR, MONTH and DAY.Function guideIFLearn Excel's IF function with practical examples: flag budgets, label rows and return blanks. Avoid the classic mistakes and practice live.Function guideANDCheck that every condition is true with Excel's AND. Use it inside IF for bonuses, ranges and eligibility rules, then try a live exercise.

Frequently asked questions

How do I check if a time is between two times in Excel?

+

Use IF with AND: =IF(AND(B2>=TIME(9,0,0),B2<TIME(17,0,0)),"Yes","No"). The time must be at or after the start and before the end. Put the start and end in cells if they change.

How do I check a time range that goes past midnight?

+

Use OR instead of AND, because the time only needs to be late in the evening or early in the morning: =IF(OR(B2>=TIME(22,0,0),B2<TIME(6,0,0)),"Night","Day").

Why does my IF time formula always return the same answer?

+

The times are probably stored as text. Text sorts above every number in Excel comparisons, so the test always comes out the same way. Convert the times with VALUE or TIMEVALUE, or use Text to Columns to turn them into real times.

How do I compare only the time when the cell also has a date?

+

Use MOD(B2,1) to keep only the time part. A date and time is a whole number for the day plus a fraction for the time, and MOD with 1 returns just the fraction.

Sources

  • IF function - Microsoft Support
  • AND function - Microsoft Support
  • MOD function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. How Excel stores times
  2. IF time between two times: the basic formula
  3. Put the start and end times in cells
  4. How to handle a time window that crosses midnight
  5. Times with dates: use MOD to compare only the time
  6. How to count the times between two times
  7. Why your IF time formula gives the wrong answer
  8. Practise it

Keep reading

Logic· 7 min read

IF Between Two Numbers in Excel

To check if a number is between two values in Excel, combine IF with AND: =IF(AND(B2>=1,B2<=5),"Standard","Other"). AND needs both tests to be true: at least the lower limit and at most the upper limit. Use > and < instead to leave out the limits themselves. Excel has no BETWEEN function, so you always write both tests.

Logic· 6 min read

IF with AND in Excel: Check Two Conditions at Once

To check two conditions at once, put AND inside IF: =IF(AND(B2>=80000,C2>=95%),"Bonus","No bonus"). AND returns TRUE only when every condition inside it is true, and IF turns that into the result you choose. You can list up to 255 conditions in AND, separated by commas. If any one is false, IF returns the false result.

Dates· 6 min read

Calculate the Difference Between Two Times in Excel

To calculate the difference between two times in Excel, subtract the start time from the end time: =C2-B2. Format the result as h:mm to see hours and minutes, or multiply by 24 to get decimal hours: =(C2-B2)*24. For shifts that end after midnight, use =MOD(C2-B2,1) so the result is never negative.

More on logic

  • How to Combine IF and VLOOKUP in Excel
  • IF With Text in Excel: Check Words and Partial Matches
  • Return Yes or No in Excel With IF
  • IFERROR in Excel: Hide Errors the Right Way
  • IFERROR Return Blank: Hide Errors With an Empty Cell
  • IFERROR With VLOOKUP: Replace #N/A With a Message
All logic articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free