Posted by Denis McMahon on 04/01/07 02:27
Arne Gemsa wrote:
> Hi,
>
> I want to get a starttime. To get this I have to subtract the runtime from a
> unit e.g. 08:40:15 from a date e.g. 2007-03-29 16:48:30. So the starttime is
> 2007-03-29 08:08:15.
>
> Is there any function in php to do so, or must I do it by myself?
Basically, convert the end time and duration into unix timestamps if
they're not already, and just do the subtraction.
With the end time and duration as a string:
$startTime = strtotime("2007-03-29 16:48:30") - strtotime("08:40:15");
With end time as a string and duration as numbers:
$duration = $durHours * 3600 + $durMinutes * 60 + $durSeconds;
$startTime = strtotime("2007-03-29 16:48:30") - $duration;
With end time as a string and duration as a timestamp:
$startTime = strtotime("2007-03-29 16:48:30") - $duration;
If end time is already a timestamp:
$startTime = $endTime - strtotime("08:40:15");
or:
$duration = $durHours * 3600 + $durMinutes * 60 + $durSeconds;
$startTime = $endTime - $duration;
or:
$startTime = $endTime - $duration;
Then, if you want the answer as a string:
$startTimeStr = strftime($startTime);
Denis McMahon
[Back to original message]
|