troubleshooting Question

Date comparison to same 'wednesday' of previous year

Avatar of tjyoung
tjyoung asked on
PHP
3 Comments1 Solution94 ViewsLast Modified:
Hi,
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?
ASKER CERTIFIED SOLUTION
JesterToo

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

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros