How to Add Days, Month, Year to Date in PHP?

03-Apr-2023

.

Admin

How to Add Days, Month, Year to Date in PHP?

Hi Dev,

This tutorial is focused on how to add days, months, and years to date in PHP. you'll learn how to add days to date in PHP. We will use how to add months to date in PHP. if you have a question about how to add years to date in PHP then I will give a simple example with a solution.

Now, let's see the article on how to add days, months, and years to date using PHP. it's a simple example of how to add days to date in PHP. you can understand the concept of how to add months to date in PHP. if you have a question about how to add years to date in PHP then I will give a simple example with a solution.

Example 1: PHP Add Days to Date


<?php

$date = "2022-01-01";

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

print_r($newDate);

?>

Output:

2022-01-04

Example 2: PHP Add Months to Date

<?php

$date = "2022-01-01";

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

print_r($newDate);

?>

Output:

2022-04-01

Example 3: PHP Add Year to Date

<?php

$date = "2022-02-01";

$newDate = date('Y-m-d', strtotime($date. ' + 5 years'));

print_r($newDate);

?>

Output:

2027-02-01

I hope it could help you...

#PHP