PHP: Generate List of dates

I am creating a website that changes its content every tuesday. Does anyone know how to create a list of dates that are Tuesdays, by specifying a start and end date. I require the format to by yyyy-mm-dd.

Thanks for your time.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The PHP date() function will take a format string and a timestamp.

Use the "w" format code to determine todays day-in-week index (Tuesday will be a 2). Use some simple arithmetic to decide how many days from today until next tuesday ((2+7 - n)%7).

Take that number, multiply it by 24 * 60 * 60 (secs/day). Add this many seconds to your timestamp. The new timestamp is a tuesday.

From this point forward (or backward) just add 7 * 24 * 60 * 60 to your timestamp and print the date out however you want using the format string in date().

For your yyyy-mm-dd format, that's going to be: date("Y-m-d", $timestamp)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.