IF Function for Dates: Excel & Sheets Guide
In this article
The IF function can absolutely work with dates in Excel and Google Sheets. You simply compare a date cell to a specific date, another cell, or the result of a date function like TODAY(), and return whatever text or value you need based on whether the condition is true or false. The key is to remember that dates are stored as serial numbers, so the comparison works like any other number comparison once you format things correctly.
How Excel and Google Sheets Store Dates
Before you write a single IF formula, it helps to understand what a date really is inside a spreadsheet. Excel and Google Sheets both store dates as sequential serial numbers starting from a base date (December 30, 1899, in Excel's default 1900 system). January 1, 2024, for example, is serial number 45292. That number is what the IF function actually compares. When you type a date like 1/1/2024 into a formula, you must wrap it in the DATE function or put it in quotation marks so the spreadsheet recognizes it as a date rather than a division problem. For instance, =IF(A1>DATE(2024,1,1),"Yes","No") is reliable, while =IF(A1>1/1/2024,"Yes","No") will divide 1 by 1 by 2024 and produce a meaningless result.
Basic Syntax for Date Comparisons
The syntax is the same as any IF formula: =IF(logical_test, value_if_true, value_if_false). The logical test is where the date comparison goes. Common operators are greater than (>), less than (<), equal to (=), and their combinations (>=, <=). Here are a few practical examples:
- Check if a date has passed:
=IF(A1<TODAY(),"Past","Upcoming") - Flag dates within a range:
=IF(AND(A1>=DATE(2024,1,1),A1<=DATE(2024,12,31)),"In 2024","Outside 2024") - Compare two date cells:
=IF(A1>B1,"Later","Earlier or equal") - Return a due status:
=IF(A1<TODAY(),"Overdue",IF(A1=TODAY(),"Due today","Not due"))
Notice the nested IF in the last example. You can nest up to 64 IF functions in Excel, but for dates it's often cleaner to use IFS or a lookup table when you have many conditions.
Common Date Functions That Work Inside IF
Several built-in functions make date logic more powerful. TODAY() returns the current date and updates every time the sheet recalculates. NOW() returns the current date and time. EDATE(start_date, months) shifts a date by a number of months, useful for calculating expiration dates. EOMONTH(start_date, months) returns the last day of a month. DATEDIF calculates the difference between two dates in days, months, or years. You can embed any of these inside an IF. For example, to check if a warranty expires within 30 days: =IF(EDATE(A1,12)-TODAY()<=30,"Expiring soon","Active"). Just be aware that TODAY() and NOW() are volatile functions—they recalculate on every change, which can slow down very large workbooks.
Formatting Pitfalls and How to Fix Them
The most common problem is that a date looks like a date but is actually stored as text. This happens when data is imported from another system or typed with an inconsistent format. You can spot it because text dates align left by default, while real dates align right. The IF function will still compare them, but text comparisons are alphabetical, not chronological, so "12/1/2024" might be considered less than "2/1/2024" because "1" comes before "2". To convert text to a real date, use DATEVALUE or the Text to Columns wizard. Another pitfall is using a date with a time component. If A1 contains 1/1/2024 14:00, it is actually serial number 45292.5833, which is greater than 45292. So =IF(A1=DATE(2024,1,1),...) will return FALSE. Use INT(A1) to strip the time, or compare with >= and < to bracket the day.
Using IF with Dates in Conditional Formatting and Data Validation
IF logic isn't limited to cell formulas. In conditional formatting, you can write a rule like =AND($A1<>"",$A1<TODAY()) to highlight overdue dates in red. In data validation, you can restrict entries to dates after today using a custom formula such as =A1>=TODAY(). These features use the same comparison engine, so the same serial-number rules apply. One caution: conditional formatting formulas are relative to the active cell, so anchor your references correctly with dollar signs.
Alternatives: IFS, SWITCH, and Lookup Tables
When you have more than two or three date-based outcomes, nested IFs become hard to read and error-prone. The IFS function (available in Excel 2019 and later, and in Google Sheets) lets you list conditions in order without nesting: =IFS(A1<TODAY(),"Overdue",A1=TODAY(),"Due today",TRUE,"Upcoming"). SWITCH is useful when you're matching exact dates, though it's less common for ranges. For complex tiered logic—like assigning a fiscal quarter based on a date—a lookup table with approximate match (VLOOKUP with TRUE) or XLOOKUP is often cleaner and easier to audit than a long IF formula.
Frequently Asked Questions
Why does my IF formula return FALSE when the dates look equal?
This usually means one date has a hidden time value, or one is stored as text. Check by temporarily formatting both cells as numbers. If they show decimals, use INT() to remove the time. If they show left-aligned text, convert with DATEVALUE.
Can I use IF to check if a date falls on a weekend?
Yes. Use the WEEKDAY function inside the logical test: =IF(WEEKDAY(A1,2)>5,"Weekend","Weekday"). The second argument 2 makes Monday=1 and Sunday=7, so values greater than 5 are Saturday and Sunday.
How do I calculate age in years using IF and dates?
Use DATEDIF: =IF(A1="","",DATEDIF(A1,TODAY(),"Y")). This returns the number of complete years between the birth date and today, and leaves the cell blank if no date is entered.
Does the IF function work the same in Google Sheets and Excel?
For date comparisons, yes—the syntax and serial-number behavior are nearly identical. Google Sheets also supports IFS and TODAY(). One difference is that Google Sheets uses December 30, 1899, as day zero, same as Excel, so serial numbers match for modern dates.
What's the maximum number of nested IFs I can use with dates?
Excel allows up to 64 nested IF functions, but practical readability suffers after three or four. Switch to IFS or a lookup table for anything more complex.
Can I use IF to return a blank cell instead of a date?
Yes. Simply use empty quotation marks as the value: =IF(A1="","",A1+30). This is handy for due-date calculations where the source cell might be empty.