Solved

Compare 2 dates and use conditional formatting if specific column has an older date

Posted on 2013-12-11
9
627 Views
Last Modified: 2013-12-12
Both column P and column R contain dates. I would like to apply conditional formatting to R2 if the date in that cell is older than the date in P2, as that flags a production issue. I only want the conditional formatting applied if both R2 and P2 have dates — if either R2 or P2 is blank, then no conditional formatting is to be applied.

What formula would I use in this situation?

Thanks in advance!
Andrea
0
Comment
Question by:Andreamary
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 39712934
Try using this formula in conditional formatting

=AND(R2<P2,R2<>"")

that can be applied to cell R2 - cell is formatted if it's older than P2 but not blank

regards, barry
0
 
LVL 81

Expert Comment

by:byundt
ID: 39713243
At risk of being a little harder to understand than the AND formula, since dates are always stored as numbers greater than 0, you could use the following Conditional Formatting formula:
=P2/R2>1

If P2 is blank, you get =0/R2>1     which becomes =0>1, which is FALSE--no Conditional Format
If R2 is blank, you get =P2/0>1      which becomes #DIV/0! error value--no Conditional Format
If R2 is later than P2, you get =P2/R2>1     but P2/R2 is less than 1--so FALSE no Conditional Format

If R2 is earlier than P2, you get =P2/R2>1   P2/R2 will be greater than 1--so test is TRUE & Conditional Format will be applied
0
 

Author Comment

by:Andreamary
ID: 39714017
My apologies to you both!!! I overlooked the fact that the dates are prefaced with initials (as per a formula implemented before my time)...sorry about that!

Here are examples of what might be in R2 or P2:

MJ–28 Dec 12
MC–20 Jan 13

Given this, is it still possible to proceed with the date compare as outlined above?

Thanks,
Andrea
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:Rob Henson
ID: 39714132
To convert each to a true date you can use:

=DATEVALUE(RIGHT(R2,LEN(R2)-3))

Assumes as per comment that only first 3 characters are note part of the date.

Thanks
Rob H
0
 
LVL 81

Expert Comment

by:byundt
ID: 39714151
If the date portion of the cell value always takes 9 characters (i.e. you use leading zeros on the day), you can use:
=RIGHT(P2,9)/RIGHT(R2,9)>1

Otherwise, you can use:
=MID(P2,FIND("-",P2)+1,20)/MID(R2,FIND("-",R2)+1,20)>1
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39714165
byundt - I went with the assumption the other way, that the non-date part was always 3 characters.

I assume you have missed out the DATEVALUE part as Excel would recognise the result as a date when calculating on it so not required. Whereas using the section of my formula without the DATEVALUE would still give a text string until it was referred to in a formula.

Thanks
Rob H
0
 

Author Comment

by:Andreamary
ID: 39714630
Correct me if I'm wrong, but it appears that to obtain the "true date" then, I would have to extract it using the formula above and create a new column for it...? If that's the case, is it possible instead, then, using VBA, to:
interpret the "true date" in column "R" and column "P" as it is currently formatted with initials first without having to extract the date and/or create another column for it
change the cell color in column "R" when the date is older than the date in the corresponding row in Column "P"
leave cell color unchanged if corresponding cells in either column "R" or "P" are blank

Thanks!
Andrea
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39715389
Andrea,
To obtain the "true date" you can either extract the date portion of the cell's text and put it in the DATEVALUE function (as suggested by Rob) or use it in an arithmetic expression (as occurs in the two formulas I suggested in my last Comment). Either way, it is not necessary to create new columns for the dates.

Using Rob's suggestion and barryhoudini's formula, the Conditional Formatting formula would be:
=AND(R2<>"",DATEVALUE(RIGHT(R2,LEN(R2)-3))<DATEVALUE(RIGHT(P2,LEN(P2)-3)))

My formulas (just repeating my previous Comment) for the Conditional Formatting formula are:
=RIGHT(P2,9)/RIGHT(R2,9)>1
=MID(P2,FIND("-",P2)+1,20)/MID(R2,FIND("-",R2)+1,20)>1

The three formulas are making different assumptions about the text in the cell:
Rob assumed there were two initials and a hyphen
My first formula assumed the date would be the last 9 characters in the cell (i.e. three for the month, two for the day and two for the year).
My second formula assumed that the initials would always be followed by a hyphen

You will need to look at how your users fill out the worksheet to determine if any of the three methods will work in all cases--or if the users need to be trained.

Brad
0
 

Author Closing Comment

by:Andreamary
ID: 39715531
Brad,

Thanks so much for an excellent explanation and summary of the 3 possible formulas, which all work! All the assumptions were correct. I will be using the shortest formula.

And thanks as well to Rob and Barry Houdini for your answers, which Brad combined for a successful formula.

Experts Exchange is an impressive resource!

Andrea
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question