How to Add Days, Month, Year to Date in PHP?
Jan 19, 2023
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...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example