How to conditionally format dates and time in Excel with formulas and inbuilt rules

If you are a regular visitor of this blog, you've probably noticed a few articles covering different aspects of Excel conditional formatting. And now we will leverage this knowledge and create spreadsheets that differentiate between weekdays and weekends, highlight public holidays and display a coming deadline or delay. In other words, we are going to apply Excel conditional formatting to dates.

If you have some basic knowledge of Excel formulas, then you are most likely familiar with some of date and time functions such as NOW, TODAY, DATE, WEEKDAY, etc. In this tutorial, we are going to take this functionality a step further to conditionally format Excel dates in the way you want.

Excel conditional formatting for dates (built-in rules)

Microsoft Excel provides 10 options to format selected cells based on the current date.

  1. To apply the formatting, you simply go to the Home tab > Conditional Formatting > Highlight Cell Rules and select A Date Occurring.
    Excel conditional formatting built-in rules for dates
  2. Select one of the date options from the drop-down list in the left-hand part of the window, ranging from last month to next month.
  3. Finally, choose one of the pre-defined formats or set up your custom format by choosing different options on the Font, Border and Fill tabs. If the Excel standard palette does not suffice, you can always click the More colors… button.
    Choose one of the pre-defined formats or set up your custom format.
  4. Click OK and enjoy the result! : )
    Highlight cells in Excel with dates occurring in the last 7 days.

However, this fast and straightforward way has two significant limitations - 1) it works for selected cells only and 2) the conditional format is always applied based on the current date.

Excel conditional formatting formulas for dates

If you want to highlight cells or entire rows based on a date in another cell, or create rules for greater time intervals (i.e. more than a month from the current date), you will have to create your own conditional formatting rule based on a formula. Below you will find a few examples of my favorite Excel conditional formats for dates.

How to highlight weekends in Excel

Regrettably, Microsoft Excel does not have a built-in calendar similar to Outlook's. Well, let's see how you can create your own automated calendar with quite little effort.

When designing your Excel calendar, you can use the =DATE(year,month,date) function to display the days of the week. Simply enter the year and the month's number somewhere in your spreadsheet and reference those cells in the formula. Of course, you could type the numbers directly in the formula, but this is not a very efficient approach because you would have to adjust the formula for each month.

The screenshot below demonstrates the DATE function in action. I used the formula =DATE($B$2,$B$1,B$4) which is copied across row 5.
Use Excel DATE function to display the days of the week.

Tip. If you want to display only the days of the week like you see in the image above, select the cells with the formula (row 5 in our case), right-click and choose Format Cells…> Number > Custom. From the drop-down list under Type, select either dddd or ddd to show full day names or abbreviated names, respectively.

Your Excel calendar is almost done, and you only need to change the color of weekends. Naturally, you are not going to color the cells manually. We'll have Excel format the weekends automatically by creating a conditional formatting rule based on the WEEKDAY formula.

  1. You start by selecting your Excel calendar where you want to shade the weekends. In our case, it is the range $B$4:$AE$10. Be sure to start the selection with the 1st date column - Colum B in this example.
  2. On the Home tab, click Conditional Formatting menu > New Rule.
  3. Create a new conditional formatting rule based on a formula as explained in the above linked guide.
  4. In the "Format values where this formula is true" box, enter the following WEEKDAY formula that will determine which cells are Saturdays and Sundays: =WEEKDAY(B$5,2)>5
  5. Click the Format… button and set up your custom format by switching between the Font, Border and Fill tabs and playing with different formatting options. When done, click the OK button to preview the rule.
    Excel conditional formatting rule with the WEEKDAY formula to highlight weekends.

Now, let me briefly explain the WEEKDAY(serial_number,[return_type]) formula so that you can quickly adjust it for your own spreadsheets.

  • The serial_number parameter represents the date you are trying to find. You enter a reference to your first cell with a date, B$5 in our case.
  • The [return_type] parameter determines the week type (square brackets imply it is optional). You enter 2 as the return type for a week starting from Monday (1) through Sunday (7). You can find the full list of available return types here.
  • Finally, you write >5 to highlight only Saturdays (6) and Sundays (7).

The screenshot below demonstrates the result in Excel 2013 - the weekends are highlighted in the reddish colour.
The weekends are highlighted in the reddish colour.

Tips:

  • If you have non-standard weekends in your company, e.g. Fridays and Saturdays, then you would need to tweak the formula so that it starts counting from Sunday (1) and highlight days 6 (Friday) and 7 (Saturday) - WEEKDAY(B$5,1)>5.
  • If you are creating a horizontal (landscape) calendar, use a relative column (without $) and absolute row (with $) in a cell reference because you should lock the reference of the row - in the above example it is row 5, so we entered B$5. But if you are designing a calendar in vertical orientation, you should do the opposite, i.e. use an absolute column and relative row, e.g. $B5 as you can see in the screenshot below:

Excel conditional formatting formula to highlight weekends in a vertical orientation calendar.

How to highlight holidays in Excel

To improve your Excel calendar further, you can shade public holidays as well. To do that, you will need to list the holidays you want to highlight in the same or some other spreadsheet.

For example, I've added the following holidays in column A ($A$14:$A$17). Of course, not all of them are real public holidays, but they will do for demonstration purposes : )
Add list of public holidays to a worksheet.

Again, you open Conditional Formatting > New Rule. In the case of holidays, you are going to use either MATCH or COUNTIF function:

  • =COUNTIF($A$14:$A$17,B$5)>0
  • =MATCH(B$5,$A$14:$A$17,0)

Note. If you have chosen a different color for holidays, you need to move the public holiday rule to the top of the rules list via Conditional Formatting > Manage Rules…

The following image shows the result in Excel 2013:
Conditional formatting formula to highlight holidays in Excel.

Conditionally format a cell when a value is changed to a date

It's not a big problem to conditionally format a cell when a date is added to that cell or any other cell in the same row as long as no other value type is allowed. In this case, you could simply use a formula to highlight non-blanks, as described in Excel conditional formulas for blanks and non-blanks. But what if those cells already have some values, e.g. text, and you want to change the background color when text is changed to a date?

The task may sound a bit intricate, but the solution is very simple.

  1. First off, you need to determine the format code of your date. Here are just a few examples:
    • D1: dd-mmm-yy or d-mmm-yy
    • D2: dd-mmm or d-mmm
    • D3: mmm-yy
    • D4: mm/dd/yy or m/d/yy or m/d/yy h:mm

    You can find the complete list of date codes in this article.

  2. Select a column where you want to change the color of cells or the entire table in case you want to highlight rows.
  3. And now create a conditional formatting rule using a formula similar to this one: =CELL("format",$A2)="D1". In the formula, A is the column with dates and D1 is the date format.

    If your table contains dates in 2 or more formats, then use the OR operator, e.g. =OR(cell("format", $A2)="D1", cell("format",$A2)="D2", cell("format", $A2)="D3")

    The screenshot below demonstrates the result of such conditional formatting rule for dates.
    A row is highlighted when text in column C is changed to a date.

How to highlight rows based on a certain date in a certain column

Suppose, you have a large Excel spreadsheet that contains two date columns (B and C). You want to highlight every row that has a certain date, say 13-May-14, in column C.

To apply Excel conditional formatting to a certain date, you need to find its numerical value first. As you probably know, Microsoft Excel stores dates as sequential serial numbers, starting from January 1, 1900. So, 1-Jan-1900 is stored as 1, 2-Jan-1900 is stored as 2… and 13-May-14 as 41772.

To find the date's number, right-click the cell, select Format Cells > Number and choose the General format. Write down the number you see and click Cancel because you do not really want to change the date's format.
Find the numerical value of a date.

That was actually the major part of the work and now you only need to create a conditional formatting rule for the entire table with this very simple formula: =$C2=41772. The formula implies that your table has headers and row 2 is your first row with data.

An alternative way is to use the DATEVALUE formula that converts the date to the number format is which it is stored, e.g. =$C2=DATEVALUE("5/13/2014")

Whichever formula you use, it will have the same effect:
Highlight every row based on a certain date in a certain column.

Conditionally format dates in Excel based on the current date

As you probably know Microsoft Excel provides the TODAY() functions for various calculations based on the current date. Here are just a few examples of how you can use it to conditionally format dates in Excel.

Example 1. Highlight dates equal to, greater than or less than today

To conditionally format cells or entire rows based on today's date, you use the TODAY function as follows:

Equal to today: =$B2=TODAY()

Greater than today: =$B2>TODAY()

Less than today: =$B2<TODAY()

The screenshot below demonstrates the above rules in action. Please note, at the moment of writing TODAY was 12-Jun-2014.
Excel formulas to highlight dates equal to, greater than or less than the current date.

Example 2. Conditionally format dates in Excel based on several conditions

In a similar fashion, you can use the TODAY function in combination with other Excel functions to handle more complex scenarios. For example, you may want your Excel conditional formatting date formula to color the Invoice column when the Delivery Date is equal to or greater than today BUT you want the formatting to disappear when you enter the invoice number.

For this task, you would need an additional column with the following formula (where E is your Delivery column and F the Invoice column):

=IF(E2>=TODAY(),IF(F2="", 1, 0), 0)

If the delivery date is greater than or equal to the current date and there is no number in the Invoice column, the formula returns 1, otherwise it's 0.

After that you create a simple conditional formatting rule for the Invoice column with the formula =$G2=1 where G is your additional column. Of course, you will be able to hide this column later.
Excel conditional formatting rule to highlight blank cells in the Invoice column when the Delivery Date is equal to or greater than today.

Example 3. Highlight upcoming dates and delays

Suppose you have a project schedule in Excel that lists tasks, their start dates and durations. What you want is to have the end date for each task calculated automatically. An additional challenge is that the formula should also consider the weekends. For example, if the starting date is 13-Jun-2014 and the number of days of work (Duration) is 2, the ending date should come as 17-Jun-2014, because 14-Jun and 15-Jun are Saturday and Sunday.

To do this, we will use the WORKDAY.INTL(start_date,days,[weekend],[holidays]) function, more precisely =WORKDAY.INTL(B2,C2,1).
The WORKDAY.INTL formula calculates the End Date for each task taking into account the weekends.

In the formula, we enter 1 as the 3rd parameter since it indicates Saturday and Sunday as holidays. You can use another value if your weekends are different, say, Fri and Sat. The full list of the weekend values is available here. Optionally, you can also use the 4th parameter [holidays], which is a set of dates (range of cells) that should be excluded from the working day calendar.

And finally, you may want to highlight rows depending on how far away the deadline is. For example, the conditional formatting rules based on the following 2 formulas highlight upcoming and recent end dates, respectively:

  • =AND($D2-TODAY()>=0,$D2-TODAY()<=7) - highlight all rows where the End Date (column D) is within the next 7 days. This formula is really handy when it comes to tracking upcoming expiration dates or payments.
  • =AND(TODAY()-$D2>=0,TODAY()-$D2<=7) - highlight all rows where the End Date (column D) is within the last 7 days. You can use this formula to track the latest overdue payments and other delays.

Excel conditional formatting rules to highlight upcoming dates and delays

Here are a few more formula examples that can be applied to the table above:

=$D2<TODAY() - highlights all passed dates (i.e. dates less than the current date). Can be used to format expired subscriptions, overdue payments etc.

=$D2>TODAY() - highlights all future dates (i.e. dates greater than the current date). You can use it to highlight upcoming events.

Of course, there can be infinite variations of the above formulas, depending on your particular task. For instance:

=$D2-TODAY()>=6 - highlights dates that occur in 6 or more days.

=$D2=TODAY()-14 - highlights dates occurring exactly 2 weeks ago.

How to highlight dates within a date range

If you have a long list of dates in your worksheet, you may also want to highlight the cells or rows that fall within a certain date range, i.e. highlight all dates that are between two given dates.

You can fulfil this task using the TODAY() function again. You will just have to construct a little bit more elaborate formulas as demonstrated in the examples below.

Formulas to highlight past dates

  • More than 30 days ago: =TODAY()-$A2>30
  • From 30 to 15 days ago, inclusive: =AND(TODAY()-$A2>=15, TODAY()-$A2<=30)
  • Less than 15 days ago: =AND(TODAY()-$A2>=1, TODAY()-$A2<15)

The current date and any future dates are not colored.
Formulas to highlight past dates in a certain date range

Formulas to highlight future dates

  • Will occur in more than 30 days from now: =$A2-TODAY()>30
  • In 30 to 15 days, inclusive: =AND($A2-TODAY()>=15, $A2-TODAY()<=30)
  • In less than 15 days: =AND($A2-TODAY()>=1, $A2-TODAY()<15)

The current date and any past dates are not colored.
Formulas to highlight future dates in a given date range

How to shade gaps and time intervals

In this last example, we are going to utilize yet another Excel date function - DATEDIF(start_date, end_date, interval). This function calculates the difference between two dates based on the specified interval. It differs from all other functions we've discussed in this tutorial in the way that it lets you ignore months or years and calculate the difference only between days or months, whichever you choose.

Don't see how this could work for you? Think about it in another way… Suppose you have a list of birthdays of your family members and friends. Would you like to know how many days there are until their next birthday? Moreover, how many days exactly are left until your wedding anniversary and other events you wouldn't want to miss? Easily!

The formula you need is this (where A is your Date column):

=DATEDIF(TODAY(), DATE((YEAR(TODAY())+1), MONTH($A2), DAY($A2)), "yd")

The "yd" interval type at the end of the formula is used to ignore years and calculate the difference between the days only. For the full list of available interval types, look here.

Tip. If you happen to forget or misplace that complex formula, you can use this simple one instead: =365-DATEDIF($A2,TODAY(),"yd"). It produces exactly the same results, just remember to replace 365 with 366 in leap years : )

And now let's create an Excel conditional formatting rule to shade different gaps in different colors. In this case, it makes more sense to utilize Excel Color Scales rather than create a separate rule for each period.

The screenshot below demonstrates the result in Excel - a gradient 3-color scale with tints from green to red through yellow.
The 3-color scale shades cells in different colors based on how many days are left until the event.

"Days Until Next Birthday" Excel Web App

We have created this Excel Web App to show you the above formula in action. Just enter your events in 1st column and change the corresponding dates in the 2nd column to experiment with the result.

If you are curious to know how to create such interactive Excel spreadsheets, check out this article on how to make web-based Excel spreadsheets.

Hopefully, at least one of the Excel conditional formats for dates discussed in this article has proven useful to you. If you are looking for a solution to some different task, you are most welcome to post a comment. Thank you for reading!

1237 comments

  1. Help with filling of todays Date. If I fill something in column B todays date must fill automatic in column A.
    Please assist

  2. So I have a list of a bunch of different Dates and i need them to turn green after 7 days have passed from that date. Ex: the original date is 1/12/22 so the box should turn green on 1/19/22 what would be the formula for this ?

  3. I have a training spreadsheet that I need to have recognize training expiring next month, this month, and expired either in previous month or months. I know can do dates occurring for this month and next month but need more then one month back. I can't remember the formula to highlight something over 30 days past.

  4. hi,
    i'm new to excel, i'm trying to figure something out. i have a list of people who need to do recurrency training every 3 years. i have the date they did las training and used a formula to automatically fill in +3 years. what i want to find out how to do is, i want the cells to be green if their training is current, yellow 6 months before training is due and red if the date has passed. can you help me with this please?

  5. Hello, i just have a question:

    I'm building a vacation planner and I would like to highlight all days between start date and end date which are going to be inserted in another excel sheet.

    In the main sheet there's the table with all days of the month/year, in another sheet there's all information about permissions and related date.

    How would you manage that using conditional formatting?

    Thanks in advance

    • Hello!
      I hope you have studied the recommendations in the tutorial above. It contains answers to your question. Pay attention to the following paragraph of the article above - How to highlight dates within a date range.

  6. I have a row with a cell dedicated for each day of the month. I'd like to average the sums in the cells based on the current date. The average should include the amounts of all cells from days in the past (including empty ones) and exclude the cells with dates in the future.
    As an example: Let's say that it's the 4th day of the month and two cells contain 10 and two cells are empty. We know the average is 5 but using =IFERROR(AVERAGE(B5:AF5),0) forces me to input a "0" in cells dated in the past.

      • Today is the 5th day of the month. Day 3 of the month (cell D5) contains 126.53.
        Following your lead I tried using =AVERAGEIF(B5:AF5, "<="&TODAY(), B5:AF5)
        That formula returns 126.53 because there is nothing else to average unless I input "0"s into cells B5, C5, E5, and F5.
        How can I tell Excel to output the average 126.53 based on the day of the month (without using zeros on the days gone past)?

          • =AVERAGEIFS(B5:AF5,B4:AF4,""">=12/31/2021",B4:AF4,"<="&TODAY()) shows some promise but results 126.53 for an average of 5 days when it should result 25.31. (If I use zeros in the other 4 cells the correct average results.)

            • Correction to above:
              =AVERAGEIFS(B5:AF5,B4:AF4,""">=12/31/2021",B4:AF4,"<="&TODAY())

            • Hi!
              To take into account empty cells in the AVERAGEIFS formula when calculating the average, try the formula

              =SUMIFS(B5:AF5,B4:AF4,"> ="&DATEVALUE("12/31/2021"),B4:AF4,"< ="&TODAY())/COUNTIFS(B4:AF4,"> ="&DATEVALUE("12/31/2021"),B4:AF4,"< ="&TODAY())

              I hope it’ll be helpful.

  7. I have a spreadsheet to track assignments. Column G contains the dates the work was assigned. Column I contains the dates when each assignment was completed. If it was completed more than 30 days from the date assigned, I would like that cell to highlight yellow. What formula would I use for this?

    For example:
    G2 shows that an assignment was made on 07/20/2021
    I2 shows that the assignment was completed on 09/13/2021

    I would like cell I2 to highlight letting me know the work was completed more than 30 days from the assigned date.

    Thank you for any guidance you're able to provide.

  8. i have a spreadsheet with a list of employee's and their different types of training. i have used conditional formatting to highlight the cell in yellow when the expiration date is 30 days away and red on the expiration date. how do i get the cell to stay red then change to no background color until a new expiration date is entered ?

      • I am using a very large spreadsheet with names, dates, merged cells. I made a column selection that holds mostly date values but also names. How can I conditional format the columns that it only changes the date cells to a certain color?

        I am using =(beginning cell)<=TODAY()-365 but blank cells and name cells are also being modified. I want it to affect only date cells.

  9. Hi can anyone help me how to formula this
    A B C D
    - 17-Jun-20 17-Jun-20 - I need this part to be Null or Zero.
    6,000.00 28-Dec-20 29-Sep-21 29-Sep-21
    50,328.00 20-Oct-20 20-Oct-20
    - 07-Jan-21 07-Jan-21 - I need this part to be Null or Zero.
    336.00 22-Mar-20 04-Oct-21 04-Oct-21
    - 22-Mar-20 04-Oct-21 04-Oct-21 - I need this part to be Null or Zero.

    in the 1st column A1 is blank then D1 should be blank as well
    I used the formula for B & C
    =MAX(IF('LPO & INVOICE (2020)'!$C$6:$C$548='LEDGER LPO & INVOICE (MIX) (2)'!C197,IF('LPO & INVOICE (2020)'!$D$6:$D$548='LEDGER LPO & INVOICE (MIX) (2)'!$G$5,'LPO & INVOICE (2020)'!$K$6:$K$548)))

    to locate the latest dates on each sheets.

    • Hi!
      It is very difficult to understand a formula that contains unique references to your workbook worksheets.
      What does the “17-Jun-20 17-Jun-20 – I need this part to be Null or Zero.” phrase mean? Your explanations are not clear.

  10. Hi! Looking to create a sheet where I can highlight based on a time frame. I need time windows every 2 hours starting at 8:30AM and ending at 4:30PM to be in one color but 4 different shades going from lighter earlier in the day to darker later in the day(Ex 8:30AM-10:30AM would be light blue, 10:30AM-12:30PM would be a darker blue and so forth). and with that same formula have it switch colors based off the name input. (Ex Mark would be blue - in four different shades. and Joe would be red - in four different shades. and Aaron would be green, etc.) That would be for a calendar month and able to put multiple on a single day. (Ex Mark has a job at 8:45AM and 2:30PM - that would be the lightest blue and darkest blue. but then joe has a job at 8:45AM, 11:00AM, and 2:30PM as well as Aaron has a job at 9:00AM and 1:00PM). How in the heck would I even do this???

  11. Thank you for this amazing support and guidance
    I am trying to use a yearly date range. For example, I have employees who have completed First Aid Courses and I need a reminder as when the qualification will expire onto a training matrix
    Would this be possible. (I have over 200 employees so impossible in Calendar.
    Thank you in advance

    • Hello!
      If the validity period expires, for example, after a year, then the conditional formatting formula can be applied to the cells in which the date of completion of the courses is written:

      =D2+365>TODAY()

  12. I have a question. I have a certification grid using values linked to another spreadsheet. I have those linked correctly, but what I now want to do is create a conditional format for the date value in the cell +650 days (because it is a certification of every 2 years). This will tell us when they are 90 days away from needing to recertify, where the cell value is the date they last certified.

    Ex. Bill certified 1/20/2020, I want to change the color of the cell so that 650 days after that date, sometime in October, the cell will turn yellow indicating they are coming due for recertification. Then another condition for red cell, when they are 30 days away (700 days after).

    Is this possible with the current rule sets in Excel?

  13. Hi, I have a gantt chart that I have a date (say 7/10/2021) in col E and the number of day (say 5) in col F. I need to have the number of days highlighted in different colours depending on the category (say painter, green highlight) in col C - with the start date on the date entered in col E. I can't seem to figure out the formula for the conditional formatting rule to achieve this. Are you able to assist?

  14. I am trying to use conditional formatting to change the colour of a cell if the time is over 4 hours, 5 hours, 9 hours for the spredsheet to correctly determine break eligibility. I've currently got the cell F4 calculating the difference in time (E4, D4), and when i go to format G4 to change colour depending on the value in F4 it wont recognise the value as it is in Time format. is there a way around this? Happy to provide screenshots.

  15. Hi there,

    I reconcile spreadsheets monthly. A report is generated the 3rd friday of every month.
    17-Sept-21 is the last date of the report. It is in cell D3. This number will get updated every month.

    Now I have 30 spreadsheets to reconcile. I don't always get to them every month.

    I want to used conditional formatting. I really would like the Icon set to appear in the Cell D beside the last reconciled date in that cell for that spreadsheet number.

    green check if is is within 30 days
    yellow ! if is is 60
    red X if it is 90.

    I had it on friday then my spreadsheet crashed and didn't auto save and I can not figure it out again.

  16. Hi

    Thank you so much your all your conditional formatting articles helped me a lot. I didn’t find an answer to only this question:
    I have a teacher working in two branches can we combine two conditional formatting rules (duplicate n between) or any other formula to prevent me giving the same time slot or in between times to same teacher in a different branch

    Ex br 1 Mr.X. 13-17

    br 2. Mr.X. 13-17 or in between times likes 15-16 ( a colour to indicate the mistake) since during that time he’s already working.

    Thank you

  17. Hi Alex,

    I hope you can help me with the following issue:
    In my school, I have created a form in which teachers can use to fill out when a student has detention. Teachers have the ability to click on the first column to select a date, put the student’s name on the next column, and so on.
    In the past, I’ve made it so that if a certain number of students are put on the list for a given day, the row turns red. Our detention room only has 12 seats, so I didn’t want teachers assigning more than 12 students each day. So, when a teacher selects the same date on a 13th row, the whole row would turn red, which they would automatically know that the detention room is full and same that entry for the next day.
    The problem I’m having is that I forgot how to create this again. Someone messed with my settings and I can’t remember how to duplicate this again.
    How can I get this done??
    Thank you!!

    Victor

    • Hello!
      This formula for the rule of conditional formatting highlights the color of all values, the number of which in the column is greater than 12.

      =COUNTIF($A$2:$A$1000,A2)>12

      I hope my advice will help you solve your task.

  18. Hello!
    Thank you for sharing...great article!

    How do you use conditional formatting in identifying date and time conflicts? Date in one column and time (24:00 format) in another column?

    Thank you!

  19. Hi,
    How do I put conditional formula for time.
    Eg : if the Time is 10:09:33
    then I want to put conditional formula as if time is before 10am or after 10 am..
    Please help

  20. Excellent blog!!! It was very helpful and was able to solve few of the problems using the techniques listed here. Thanks a ton and keep sharing your knowledge.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)