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]
|