Jump to content

Working with dates

Recommended Posts

Suppose i wanna make a page where a customer enters, and he will see the days of the next week, like if im entering the page today (wednesday september 6th) i will see a table with the following week, starting from sunday september 10th to saturday september 17th. 

is there a way php can do such thing?

Link to post
Share on other sites

Use string to time function strtotime(), you can multitude textual expression to get the result you want, then loop through each day by increasing by 1 in a loop


// set initial start date to next sunday from current date
        $date = date("Y-m-d", strtotime("next Sunday"));

//set from $date value to 1 week ahead for end date
        $end_date = date("Y-m-d", strtotime("+1 week", strtotime($date))); //'2020-12-31';

        while (strtotime($date) <= strtotime($end_date)) {
            echo $date . "<br>";
            //increment to next day
            $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));


  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...