You are here: Re: Calculating the difference « PHP Programming Language « IT news, forums, messages
Re: Calculating the difference

Posted by Bruno Barros on 10/01/07 14:11

On 1 Oct, 14:49, Julius <julius.ehrl...@googlemail.com> wrote:
> Hej dudes,
>
> I need to calc the difference between two timestamps / dates ...
>
> For example what i need to calculate:
>
> Date 1: 2007.11.06 - 20:13:04
> Date 2: 2007.11.07 - 21:13:04
>
> Difference: 1 day, 1hour
>
> Very simple in php ..
>
> but how do i calculate the difference between the following values:
>
> Date 1: 2007.11.06 - 20:13:04
> Date 2: 2007.11.08 - 03:13:04
>
> Does someone have a quick solution for this ?
> Thanks ahead ...

First, http://pt.php.net/manual/en/function.strtotime.php. Then
$later_time - $earlier_time.

$date1 = '2005-12-25 00:56:27 GMT' ; // Note the timezone
specification
$time1 = strtotime($date1) ;
$date2 = '2005-12-27 05:56:27 GMT' ; // Note the timezone
specification
$time2 = strtotime($date2) ;

$difference = $time2 - $time1;

print date('z \d\a\y\s\, H:i:s', $difference - 3600); // X days,
Hours:Minutes:Seconds

I added - 3600 because it was showing 01:00:00 even when $difference
was 0. Probably DST thingie.

 

Navigation:

[Reply to this 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

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