[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-12-11
9
Medium Priority
?
831 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

649 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