How to Add Days to Date and Reduce Days from Date in PHP
Last Update : 15 Dec, 2022In this article, you will learn to add days to the date. And also, reduce days from the date.
When you are working with PHP based project, you need to add days to the date and also you need to reduce days from the date.
Here is the best solution to add days and reduce days.
Add days to the date
The following example shows to add 10 days to the date of 2022-11-10 using PHP.
<?php
$date = "2022-11-10";
echo date('Y-m-d', strtotime($date. ' + 10 days'))
?>
This program produces the following result -:
2022-11-20
Reduce days from the date
The following example shows reduce 7 days from the date of 2022-11-10 using PHP.
<?php
$date = "2022-11-10";
echo date('Y-m-d', strtotime($date. ' - 7 days'));
?>
This program produces the following result -:
2022-11-03
Add days to the current date. And reduce the date from the current date
The following example shows to add 5 days to the current date and also reduce 5 days from the current date.
<?php
// Add 5 days
echo date('Y-m-d', strtotime(' + 5 days'));
// Reduce 5 days
echo date('Y-m-d', strtotime(' - 5 days'));
?>