How do I use an IF function with time in Microsoft Excel?


You can use the following formulas to create an IF function with times in Excel:

Method 1: Create IF Function to Compare Time in Cell with Specific Time

=IF(B2<=TIMEVALUE("9:00"), "Yes", "No")

This formula checks if the time in cell B2 is equal to or before 9:00 AM and returns “Yes” or “No” accordingly.

Method 2: Create IF Function to Compare Times in Two Cells

=IF(A2<=B2, "Yes", "No")

This formula checks if the time in cell B2 is equal to or before the time in cell C2 and returns “Yes” or “No” accordingly.

The following examples show how to use each formula in practice.

Example 1: IF Function to Compare Time in Cell with Specific Time

Suppose we have a list of times in Excel that show when some task was done and we want to know if each task was done by 9:00 AM:

We can type the following formula into cell C2 to return “Yes” if the task in cell B2 was done by 9:00 AM or return “No” otherwise:

=IF(B2<=TIMEVALUE("9:00"), "Yes", "No")

We can then drag and fill this formula down to each remaining cell in column C:

The formula returns either “Yes” or “No” depending on whether or not the time in column B is before or equal to 9:00 AM.

Note: The TIMEVALUE function in Excel converts a time stored as a text value to a time that is recognizable by Excel formulas.

Example 2: IF Function to Compare Times in Two Cells

Suppose we have two columns of times in Excel that show when some task was completed along with the task deadline:

We can type the following formula into cell C2 to return “Yes” if the task in cell A2 was done before or on the deadline time in cell B2 or to return “No” if it wasn’t:

=IF(A2<=B2, "Yes", "No")

We can then drag and fill this formula down to each remaining cell in column C:

The formula returns either “Yes” or “No” depending on whether or not the task in each row was completed by the deadline time.

x