How to Subtract Days to Date in PHP?

In this blog, we will understand how to subtract days from dates using PHP. This is used in many projects for filtering and report generation. 


I will explain this using simple examples.


Let's get started,


Subtract Days to Date PHP


<?php

  

    $date = "2023-06-04";

    $newDate = date('Y-m-d', strtotime($date. ' - 3 days'));

  

    echo $newDate;

  

?>


Output:


2023-06-01



Subtract Days to Current Date


<?php

  

    $newDate = date('Y-m-d', strtotime(' - 3 days'));

  

    echo $newDate;

  

?>



Output:


2023-05-31


I hope this is simple to understand. If you have any doubt let me know in comments.