Inside this article we will see a basic concept of PHP i.e How to add days to date in PHP. Article contains classified information about adding days to a specific date or even with current date in PHP.
We need this concept i.e adding days, remove days from a specific date is when we are creating some record type applications.
In PHP there are several functions which provides the function to add number of days into date. This concept will give you the understanding of adding 5 days, 7 days, 30 days etc into date.
Learn More –
- Find and Extract All Images From a Web Page in PHP
- Find and Extract All links From a HTML String in PHP
- How To Generate Fake Data in PHP Using Faker Library
- How to Generate Fake Image URLs in PHP Using Faker
Let’s get started.
Example 1: Add 5 days to a Specific date
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $date = "2021-10-01"; $newDate = date('Y-m-d', strtotime($date. ' + 5 days')); echo $newDate; ?>
Output
2021-10-06
Example 2: Add 10 days to a Specific date
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $date = "2021-10-01"; $newDate = date('Y-m-d', strtotime($date. ' + 10 days')); echo $newDate; ?>
Output
2021-10-11
Example 3: Add 5 days to current date
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $newDate = date('Y-m-d', strtotime(' + 5 days')); echo $newDate; ?>
Output
2021-11-08
Example 4: Add 10 days to current date
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $newDate = date('Y-m-d', strtotime(' + 10 days')); echo $newDate; ?>
Output
2021-11-13
We hope this article helped you to learn How to Add Days to Date in PHP Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.