You are here: Re: PHP Time Bug « PHP Programming Language « IT news, forums, messages
Re: PHP Time Bug

Posted by Andy Hassall on 02/03/06 00:42

On 2 Feb 2006 14:01:54 -0800, "Tomas" <tomas.srna@gmail.com> wrote:

>I have a very interesting problem...
>Php says that the difference between these times is 1 hour.
>
><?php
>$t1 = "2005-12-31 20:00";
>$t2 = "2005-12-31 20:00";
>$t1i = strtotime($t1);
>$t2i = strtotime($t2);
>$diff = abs($t1i - $t2i);
>print_r(getdate($diff));
>?>
>
>The Output:
>Array
>(
> [seconds] => 0
> [minutes] => 0
> [hours] => 1
> [mday] => 1
> [wday] => 4
> [mon] => 1
> [year] => 1970
> [yday] => 0
> [weekday] => Thursday
> [month] => January
> [0] => 0
>)

What you've ended up asking with the code above is "what is the year, month,
day and time of the difference of two identical times?" - which doesn't make
much sense.

You end up with "what is the date represented by the value zero", which is
defined as the "UNIX epoch". Apparently you're in a central European country
currently on GMT+1 (Slovakia from the looks of your message headers?); the UNIX
epoch is midnight 1st Jan 1970 GMT - the result you've got is 1am on the same
day, as adjusted for your timezone.

>Can you please suggest something how to calculate the difference
>between 2 datetimes?

Depends what you really want. You already had the difference in seconds -
zero. You can divide this down to get hours or days, but it depends how you
want to deal with summer time transitions.

>And another question, a bit off-topic, but how do I get the number of
>days of a month with taking leap years in consideration?

The "t" option in http://uk2.php.net/date
Or http://uk2.php.net/calendar

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

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

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