PHP: Generate List of dates

Posted on 2006-04-07
Last Modified: 2008-03-10
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.
Question by:markgales
    1 Comment
    LVL 1

    Accepted Solution

    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)


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    calling Tcolordialog in dll make the form disappear 8 78
    equalIsNot  challenge 43 90
    static class 3 44
    countHi challenge 25 61
    Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    This video teaches viewers about errors in exception handling.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now