Avatar of Bruce Gust
Bruce Gust
Flag for United States of America asked on

How can I get two dates to be compared to one another in the context of a loop?

How would I compare two dates in the context of a loop?

I've got a table full of duplicates. I've been able to craft a foreach loop that accurately retrieves and displays duplicate values. But then, when I've got two duplicates to consider, I need to compare the dates and be able to give the user the opportunity to click a button that will delete the date that is the oldest.

I'm coming up short.

Here's what I've been trying:

foreach($current_list as $current)
		//I've got a duplicate
				echo "a rebel yell";
				echo "say nothing";

Open in new window

It's not working. I've tried several different configurations and I'm ooen to suggests.

Any ideas?

Avatar of undefined
Last Comment
Bruce Gust

8/22/2022 - Mon
David Favor

Easy way is to convert all your dates to seconds, then just do simple arithmetic + convert results to human readable form, if required.

I can see a few issues with the code you've supplied... Did you redact much more of the code as that wouldn't run without errors for me.

The following will always return true

Open in new window

Did you mean one of them to be the variable $current_ssn ?

Your "if" statement was missing a closing right bracket:

I'm working on a solution for you that i'll post soon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Bruce Gust

Thanks, guys! And yes, Rob, in this case I'm expecting all the duplicates to be listed right next to one another.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck