How to know PHP version ?
Here is an example on how to use modify function.
<?Php
date_default_timezone_set ("Asia/Kolkata");
$date1=new DateTime("now") ; // current date
echo $date1->format('d-m-Y');
echo "<br>";
$date2=$date1->modify('+5 day');
echo $date2->format('d-m-Y');
?>
The output is here
09-09-2026
14-09-2026
We can change the highlighted line like this
$date2=$date1->modify('+3 month +5 day -1 year ');
Output of this change is here
09-09-2026
14-12-2025
<?Php
date_default_timezone_set ("Asia/Kolkata");
$date1=new DateTime("now") ;
echo $date1->format('d-m-Y H:i:s');
echo "<br>";
$date2=$date1->modify('+5 day +6 hours +20 minutes +30 seconds ');
echo $date2->format('d-m-Y H:i:s');
?>
Output is here ( based on today's date and time). Refresh this page and check the changes in time.
09-09-2026 22:24:35
15-09-2026 04:45:05
$date = new DateTime('2024-02-29 12:00:00');
$date2=$date->modify('+1 year +5 hours');
echo $date2->format('d-m-Y H:i:s');
Output is here01-03-2025 17:00:00PHP Date Functions
Timestamp in PHP Displaying calendar for selection of date by user
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.