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;
}
?>
…
Website: tanzilo.files.wordpress.com | Filesize: 34kb
No of Page(s): 2
Click here to download PHP script to add time. Tutorial with code and example.
Related Tutorial
Tags: basic
Comments
Leave a Reply