# Same day last year problem

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hey,

Today is Thursday 16-Feb-06.  The same thursday last year is 17-Feb-05.
Because I am comparing daily sales between years, I need to know the
date of the same weekdayname as last year, so that I am comparing
Saturdays with Saturdays, Sundays with Sundays, etc

ie, 16-feb-06 goes to 17-feb-05
28-july-06 goes to 27-july-05 and so on

I have tried all sorts of dateadd('2004-01-01'............. etc, and I
am all out of ideas.

Any suggestions would be very much appreciated.

Thanks
Ryan

## Re: Same day last year problem

rjfjohn...@hotmail.com wrote:

Essentially, you need to know the date that was 52 weeks before today:

\$today = time();
\$year_ago = \$today - 52*7*24*60*60;
\$today_date = date('Y-m-d', \$today);
\$year_ago_date = date('Y-m-d', \$year_ago);

Now you can use \$today_date and \$year_ago_date in a query...

Cheers,
NC

## Re: Same day last year problem

Thank you so much,

You have saved me so much time, I think im an idiot

## Re: Same day last year problem

NC,

I tried that function - it works rather well except, it doesnt seem to
take into account leap years.

Who in their right mind would invent a leap year!!!???

Any suggestions to jump over this hurdle?

Ryan

## Re: Same day last year problem

Try:

\$d=strtotime("-1 year");

dave

## Re: Same day last year problem

Blame the solar system! :-)

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)

## Re: Same day last year problem

Personally I beleive that there should be 10 days per week, 10 weeks
per month and 10 months per year, with 10 hours per day, 100 minutes
per hour, 100 seconds per minute, and we should just suffer with out of
phase moons, etc.

Besides, its not like we need the stars for navigation any more

## Re: Same day last year problem

rjfjohnson@hotmail.com wrote:

The French actually tried almost that exact system shortly after the French
Revolution, when they were trying to shed all remnants of the "old ways".

http://en.wikipedia.org/wiki/French_Revolutionary_Calendar

It did not have happy results.  Workers objected to having their weekly day
off of work come once every 10 days instead of once every 7...
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

## Re: Same day last year problem

rjfjohnson@hotmail.com wrote:

Ryan,

I'm confused.  NC's code works fine.  Extrapolating it for several years
(and formatting to get the day of the week), I get:

Today is Thursday, February 16, 2006
1 years ago was Thursday, February 17, 2005
2 years ago was Thursday, February 19, 2004
3 years ago was Thursday, February 20, 2003
4 years ago was Thursday, February 21, 2002
5 years ago was Thursday, February 22, 2001
6 years ago was Thursday, February 24, 2000
7 years ago was Thursday, February 25, 1999
8 years ago was Thursday, February 26, 1998
9 years ago was Thursday, February 27, 1997
10 years ago was Thursday, February 29, 1996

This is fine for the last few years, but eventually (when you get seven
extra days, Year 2000 in this example) it's off a week.
But for the last 3-4 years it should be fine.

What is different about what you're looking for?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Same day last year problem

Jerry, NC,

You are right.  I didn't copy it correctly.

Thanks again,
Ryan