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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...