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

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Get DNS Records programmatically lookup
  2.   PHP MySQL Autocomplete textbox using jQuery
  3.   laravel 5/6/7 open link in new tab Example
  4.   PHP Secure Token Generator Authentication tutorial
  5.   Create dynamic calendar using jQuery, Ajax and PHP
  6.   How to Check If Array is Empty in Laravel Blade?
  7.   Enable/Disable debug mode in cakephp
  8.   Table Columns Sorting with OrderBy Filter using Angular Example
  9.   Get Current login Auth user details using Laravel 5.7
  10.   How to Make a Redirect to page in PHP?