PHP Add Days Hours Minutes and Seconds to Datetime

PHP Add Days Hours Minutes and Seconds to Datetime

In this Post We Will Explain About is PHP Add Days Hours Minutes and Seconds to Datetime With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Add a duration or interval to a dateExample

In this post we will show you Best way to implement How to adds and substracts some days, months, years, hours, minutes, hear for Adds an amount of days, months, years, hours, minuteswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to add Days, Hours, Minutes, and Seconds to Datetime in PHP

Add days to datetime using PHP.
Add date functions to hours to datetime using PHP.
Add date functions to minutes to datetime using PHP.
Add date functions to seconds to datetime using PHP.

How to adds and substracts some days, months, years, hours, minutes

echo "<hr />";
$firstStartDateTime = date("Y-m-d H:i:s");

//display the starting time using PHP
echo 'Starting Time: '.$firstStartDateTime;

//add 2 hour to time using PHP
$FinalDateTime = date('Y-m-d H:i:s',strtotime('+2 hour',strtotime($firstStartDateTime)));

//display the FinalDateTime time using PHP
echo 'FinalDateTime Time (added 2 hour): '.$FinalDateTime;

//add 2 hour and 20 minutes to time using PHP
$FinalDateTime = date('Y-m-d H:i:s',strtotime('+2 hour +20 minutes',strtotime($firstStartDateTime)));

//display the FinalDateTime time using PHP
echo 'FinalDateTime Time (added 2 hour & 20 minutes): '.$FinalDateTime;

//add 2 hour, 20 minutes and 30 seconds to time using PHP
$FinalDateTime = date('Y-m-d H:i:s',strtotime('+2 hour +20 minutes +30 seconds',strtotime($firstStartDateTime)));

//display the FinalDateTime time using PHP
echo 'FinalDateTime Time (added 2 hour, 20 minutes  & 30 seconds): '.$FinalDateTime;

//add 2 day, 2 hour, 20 minutes and 30 seconds to time using PHP
$FinalDateTime = date('Y-m-d H:i:s',strtotime('+2 day +2 hour +20 minutes +30 seconds',strtotime($firstStartDateTime)));

//display the FinalDateTime time using PHP
echo 'FinalDateTime Time (added 2 day, 2 hour, 20 minutes  & 30 seconds): '.$FinalDateTime;
echo "<hr />";

Example

Also Read This ๐Ÿ‘‰   myisam vs innodb - difference between innodb and myisam

I hope you have Got What is How to add Days, Hours, Minutes, and Seconds to Datetime in PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.