Reply to Re: subtract time from a date

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация