How can I get last week’s date range in PHP?

Date is important function in php.

This is a short guide on How to get last week date range monday to sunday in PHP. This is useful for whenever you need to figure out what date a particular date fell on (or will fall on in the future). In this tutorial, I will be retrieving the date from a YYYY-MM-DD string.

PHP Code

<?php
    $previous_week = strtotime("-1 week +1 day");
    $start_week = strtotime("last monday midnight",$previous_week);
    $end_week = strtotime("next sunday",$start_week);

    $start_week = date("Y-m-d",$start_week);
    $end_week = date("Y-m-d",$end_week);

    echo $start_week.'<br /> '.$end_week ;
?>

OUTPUT

2018-11-19
2018-11-25

Leave a Reply

Your email address will not be published. Required fields are marked *