- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add days to $Date in PHP?
To add days to $Date in PHP, the code is as follows−
Example
<?php $date = "2019-11-11"; echo "Displaying date...
"; echo "Date = $date"; echo "
Displaying updated date...
"; echo date('Y-m-d', strtotime($date. ' + 20 days')); ?>
Output
This will produce the following output−
Displaying date... Date = 2019-11-11 Displaying updated date... 2019-12-01
Example
Let us now see another example −
<?php $date = date_create("2019-11-11"); echo "Displaying Date..."; echo date_format($date,"Y/m/d"); date_add($date, date_interval_create_from_date_string("25 days")); echo "
Displaying Updated Date..."; echo "
".date_format($date, "Y/m/d"); ?>
Output
This will produce the following output−
Displaying Date...2019/11/11 Displaying Updated Date... 2019/12/06
Advertisements