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

Posted by Marc van Lieshout on 02/03/06 00:23

"Tomas" <tomas.srna@gmail.com> wrote in message
news:1138917713.942658.239590@z14g2000cwz.googlegroups.com...
>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
> )
>
> Can you please suggest something how to calculate the difference
> between 2 datetimes?
>
> 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?
>
> Thanks in advence.
> Tomas
>

function is_leap_year($year) {
return (($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400 == 0);
}

function days_in_month($month, $year) {

switch ($month) {
case 4:
case 6:
case 9:
case 11:
return 30;

case 2:
return is_leap_year($year) ? 29 : 28;

default:
return 31;
}
}


Marc.

 

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

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