Wednesday, September 3, 2008

php Subtract the Time

<?php

function subtractTime($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;

}

// Let us first see the current time

echo "Current Time:"  . date("Y-m-d H:i:s A");

echo "<BR>";

// Now let us deduct 5 hours, 2 days and 1 year from now

echo "New Time: " .subtractTime(0,15,0,2,0,0);

?>

No comments:

Post a Comment