PHP Script to Add Time. Tutorial With Code and Example
with keywords like PHP Add Time. As this is happening frequently, … So, I hope the people who were looking for a PHP example to add time and eventually …
More PDF Content
PHP script to add time. Tutorial with code and example
Page 1
PHP script to add time. Tutorial with code and example Some days ago I wrote an article on how to get the local time. But I saw that many people are searching with keywords like “PHP Add Time”. As this is happening frequently, I have decided to write an article on how to add time using PHP. Here is the article. In this article, I have written a function that takes hour, minute, second, day, month and year as inputs, adds all supplied time values and returns the new time. So, you can add hours, minutes, seconds, days, months and years with current time by supplying only 6 inputs when you call the function. Okay. Here is the PHP function to add time. function addTime($hours=0, $minutes=0, $seconds=0, $months=0, $days=0, $years=0) { $totalHours = date(”H”) + $hours; $totalMinutes = date(”i”) + $minutes; $totalSeconds = date(”s”) + $seconds; $totalMonths = date(”m”) + $months; $totalDays = date(”d”) + $days; $totalYears = date(”Y”) + $years; $timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds, $totalMonths, $totalDays, $totalYears); $myTime = date(”Y-m-d H:i:s A”, $timeStamp); return $myTime; } ?> Now we call the function to test the output. // Let us first see the current time echo ‘Current Time: ‘ . date(”Y-m-d H:i:s A”); echo ‘
‘; // Now let us add 2 hours and 10 minutes from now echo ‘New Time: ‘ . addTime(2,10,0,0,0,0); ?>
Page 2
Thus, this is so simple to add time using PHP. So, I hope the people who were looking for a PHP example to add time and eventually came to my article on how to find local time would get the right article.
Processing your request, Please wait....