The IF function is one of the most useful Excel functions. It is used to test a condition and return one value if the condition is TRUE and another if it is FALSE.

One of the most common applications of the IF function involves the comparison of values.

These values can be numbers, text, or even dates. However, using the IF statement with date values is not as intuitive as it may seem.

In this tutorial, I will demonstrate some ways in which you can **use the IF function with date values**.

Table of Contents

## Syntax and Usage of the IF Function

The syntax for the IF function is as follows:

IF(logical_test, [value_if_true], [value_if_false])

Here,

*logical_test*is the condition or criteria that you want the IF function to test. The result of this parameter is either TRUE or FALSE*value_if_true*is the value that you want the IF function to return if the*logical_test*evaluates to TRUE*value_if_false*is the value that you want the IF function to return if the*logical_test*evaluates to FALSE

For example, say you want to write a statement that will return the value “*yes*” if the value in cell reference A2 is equal to the 10, and “*no*” otherwise. You can then use the IF function as follows:

=IF(A2=10,"yes","no")

## Comparing Dates in Excel

Unlike numbers and strings, comparison operators when used with dates, have a slightly different meaning.

Here are some of the comparison operators that you can use when comparing dates, along with what they mean:

Symbol |
Meaning |

< | Is before |

= | Is the same as |

> | Is after |

<= | Is the same as or before |

>= | Is the same as or after |

## Using IF Function with Dates in Excel

It may look like IF formulas for dates are the same as IF functions for numeric or text values, since they use the same comparison operators. However, it’s not as simple as that.

Unfortunately, unlike other Excel functions, the IF function cannot recognize dates. It interprets them as regular text values. So you cannot use a logical test as *“>05/07/2021*” in your IF function, as it will simply see the value “*05/07/2021*” as text.

Here are a few ways in which you can incorporate date values into your IF function’s *logical_test* parameter.

### Using the IF Function with DATEVALUE Function

If you want to use a date in your IF function’s logical test, you can wrap the date in the DATEVALUE function. This function converts a date in text format to a serial number that Excel can recognize as a date.

If you put a date within quotes, it is essentially a text or string value. When you pass this as a parameter to the DATEVALUE function, it takes a look at the text inside the double quotes, identifies it as a date and then converts it to an actual Excel date value.

Let us say you have a date in cell A2 and you want cell B2 to display the value “*done*” if the date comes before or on the same date as “*05/07/2021*” and display “*not done*” otherwise. You can use the IF function along with DATEVALUE in cell B2 as follows:

=IF(A2<DATEVALUE("05/07/2021"),"done","not done")

Here’s a screenshot to illustrate the effect of the above formula:

### Using the IF Function with the TODAY Function

If you want to compare a date with the current date, you can use the IF function with the TODAY function in the logical test.

Let’s say you have a date in cell A2 and you want cell B2 to display the value “done” if it is a date before today’s date. If not, you want let’s say you want to display the value “not done”. You can use the IF function along with the TODAY function in cell B2 as follows:

=IF(A2<TODAY(),"done","not done")

Here’s a screenshot to illustrate the effect of the above formula (assuming the current date is 05/08/2021):

### Using the IF Function with Future or Past Dates

An interesting thing about dates in Excel is that you can perform addition and subtraction operations with them too. This is because dates are basically stored in Excel as serial numbers, starting from the date *Jan 1, 1900*.

Each day after that is represented by one whole number.

So, the serial number 2 corresponds to *Jan 2, 1900,* and so on.

This means, adding *n* number of days to a date is equivalent to adding the value *n* to the serial number that the date represents.

If TODAY() is *05/07/2021*, then TODAY()+5 is five days after today, or *05/12/2021*. Similarly, TODAY()-3 is three days before today or *05/04/2021*.

Let’s say you have a date in cell A2 and you want cell B2 to mark it as “*within range*” if it is within 15 days from the current date. If not, you want to show “*out of range*”. You can use the IF function along with the TODAY function in cell B2 as follows:

=IF(A2<TODAY()+15,"within range","out of range")

Here’s a screenshot to illustrate the effect of the above formula (assuming the current date is 05/08/2021):

## Points to Remember

Having discussed different ways to use dates with the IF function, here are some important points to remember:

- Instead of hardcoding the dates into the IF function’s logical test parameter, you can store the date in a separate cell and refer to it with a cell reference. For example, instead of typing =IF(A2<”05/07/2021”,”done”,”not done”), you can store the date
*05/07/2021*in a cell, say B2 and type the formula: =IF(A2<B2,”done”,”not done”). - Alternatively, you can use the DATEVALUE function as explained in the first part of this tutorial.
- Another neat technique that you can use is to simply add a zero to the date (which has been enclosed in double quotes). So you can type: =IF(A2<”05/07/2021”+0,”done”,”not done”). This will make Excel take the date inside double quotes as a serial number, and use it in the logical test without having its value changed.

In this tutorial, I showed you some great techniques to use the IF function with dates. I hope the tips covered here were useful for you.

**Other articles you may also like:**