# PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

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

•  Subject
• Author
• Posted on
Hello,

How can I determine what the date was (in YYYY-MM-DD format) last
Sunday, and the Sunday before that?

For example:

Today is Thursday, August 18, 2004 (2004-08-18). I would like to have
the following variables:

\$this_past_sunday = 2004-08-14
\$two_sundays_ago = 2004-08-07
\$three_sundays_ago = 2004-07-31

etc. etc.

Thank you very much for your help in figuring this out!

- Eric

## Re: PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

See my reply to your other post and you should be able to get it from there.

Steve
--
Steven C. Gallafent - The Computer Guy, Inc.
steve@compguy.com - http://www.compguy.com /

## Re: PHP Date Question: How to Determine The Date Each of the Past3 Sundays

Eric,

Clues for you, the rest is up to you to figure out.

This example would determine two dates based on epochs:

\$month, \$day, \$year are up to you.

\$this_epoch      = date( "U", mktime ( 0,0,0, \$month, \$day, \$year ) );
\$next_epoch      = \$this_epoch + 604800 ;
\$next_ts         = date( "Y-m-d H:i:s", date ( \$next_epoch ) ) ;

Solve:

\$last_week_epoch     = \$this_epoch - ?
\$two_weeks_ago_epoch = \$this_epoch - ?

Have fun!

-DG-

Eric Linders wrote:

## Re: PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

I would do something like

\$7daysInSeconds = 86400 * 7;
\$lastSunday = strtotime("last sunday");
\$two_sundays_ago = \$lastSunday - \$7daysInSeconds;
\$three_sundays_ago  = \$two_sundays_ago - \$7daysInSeconds;

then format however you like. e.g.
\$lastSundayString = date('Y-m-d', \$lastSunday) ;
etc...

--
Rob...