Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Date comparison to same 'wednesday' of previous year

Avatar of tjyoung
tjyoung asked on
3 Comments1 Solution94 ViewsLast Modified:
Been struggling with dates... again. And this could be a stupid question, so bear with me.
Today's issue is trying to compare the sales we did yesterday, (in my example lets say yesterday was Wednesday March 29, 2017), to one year ago (but the same wednesday, not simply 365 days ago as that would give me the wrong week day). In 2016 the Wednesday was March 30, 2016

I'm getting various dates for comparison like below:
$yesterday = Carbon::yesterday()->format('Y-m-d');
lastyear = Carbon::yesterday()->subMonths(12)->addDays(1)->format('Y-m-d');

This returns me the correct days for comparison. My question is... will this always work? Adding one day?
Avatar of JesterToo
JesterTooFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers