Conditionally Formatting Dates in Excel [Part 1 of 2]

Posted on January 5th, 2010 in Excel Howtos , Learn Excel - 6 comments

This is first part of 2 part series on conditionally formatting dates in excel.

Conditional formatting is a very useful feature in Excel. You can use Conditional formatting to tell excel how to format cells that meet certain conditions. For eg. You can use conditional formatting to show all negative values in a range in red color. [Learn conditional formatting basics].

Today we will learn how to use conditional formatting to format dates.

Click on the below links to jump to relevant section.
Excel 2007+ – Conditional Formatting Dates
Excel 2003 – Conditional Formatting Dates

Excel 2007+ – Conditional Formatting Dates

Excel 2007 - Conditional Formatting Dates - menu

In Excel 2007, MS introduced several useful shortcuts to conditionally format dates. When you select some cells and click on Conditional Formatting button on ribbon and select “Highlight cells Rules” > “A date occurring”, Excel presents you quick shortcuts to frequent date criteria. This list includes options to format,
Excel 2007 - Conditional Formatting Dates

  • A Date if it is yesterday
  • Today
  • Tomorrow,
  • In the last 7 days
  • Last week
  • This Week
  • Next Week
  • Last Month
  • This Month
  • Next Month

Using this feature, you can quickly format the dates in your data meeting certain criteria.

This is very useful in situations where you want to highlight for eg. sales in last week. As the dates change, the highlighted values change dynamically.

Apart from these predefined date conditions, you can define your own conditions using formulas.

Excel 2003 – Conditional Formatting Dates

Unlike Excel 2007, there are no shortcuts for conditional date formatting in Excel 2003. You have to rely on Conditional Formatting Formulas to do this.

What is a conditional formatting formula?
In excel you can use formulas to determine which cells get the special formatting thru conditional formatting. For eg. a formula like =A1>50 applied over the range A1:A10 will highlight the cells with value more than 50.

So, to check if the date in cell A1 is yesterday, you can write a simple formula like,
=TODAY()-A1=1. [help on TODAY formula]

Excel 2003 - Conditional Formatting Dates

Here are some formulas to get you started,

  • To check if a date is in the last 7 days:
    =TODAY()-A1<7
  • To check if a date is in the current week:
    =AND(WEEKNUM(A1)=WEEKNUM(TODAY()), YEAR(A1)=YEAR(TODAY()))
  • To check if a date is in the current month:
    =AND(MONTH(A1)=MONTH(TODAY()), YEAR(A1)=YEAR(TODAY()))
  • To check if a date is in the last 30 days:
    =TODAY()-A1<30

[Help on AND formula, MONTH formula, YEAR formula, IF formula]

Using above formula based conditional formatting you can easily determine if a date meets a given criteria and highlight it.

A Practical Application – Highlighting Repeat Customers

Let us say you run a small retail store. And you want to give special discounts to all the repeat customers. In your mind a repeat customer is someone who bought twice from you in last 30 days. (If the person bought twice but the gap between 2 purchases is more than 30 days they are not repeat customers).

In tomorrow’s post I will show you how to highlight repeat customers using excel conditional formatting. Stay tuned.

Learn more about Excel Conditional Formatting

Join our email news letter:

If you like this article, please join our mailing list. You will get an excel tip every weekday. Also, you will get a free copy of my 95 excel tips e-book. Click here to join.

| More
Subscribe for PHD Email updates and get a free excel e-book with 95 tips & tricks

Comments
Rick Rothstein (MVP - Excel) January 5, 2010

I think you have a typo in your 2nd date formula. You posted this…

=AND(WEEKNUM(A1)=WEEKNUM(A1), YEAR(A1)=YEAR(TODAY()))

I think you meant this…

=AND(WEEKNUM(A1)=WEEKNUM(TODAY()), YEAR(A1)=YEAR(TODAY()))

Chandoo January 5, 2010

@Rick.. My mistake. Thanks for pointing it out. I have corrected it now.

Kim_Office_Team January 6, 2010

Thanks for blogging about Excel and some of the conditional formatting features. I’m sure the folks over at Excel would appreciate you sharing your expertise with the community!

Check out the Office page on Facebook at http://www.facebook.com/Office.

Cheers,
Kim
MSFT Office Outreach Team

taj kumar February 3, 2010

Dear Sir,

how to prepare the result chart on excel ?Please advice me?

Thanks

Chandoo February 3, 2010

@Taj… what do you mean by result chart?

RSS feed for comments on this post. TrackBack URI

Leave a comment

   Name (required)

   E-mail (required, never displayed)

   URL


If you have a question, please ask in the forums

Recommended Excel, Charting, VBA books