|
Posted by Pedro Graca on 02/03/06 01:17
Tomas wrote:
> I have a very interesting problem...
> Php says that the difference between these times is 1 hour.
No it doesn't
> <?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));
> ?>
What PHP says is that getdate(0) returns the following
> 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?
You already did that.
The difference between $t1 and $t2 is 0 (seconds); if you want to
convert seconds to hours divide by 3600
echo 'Difference is ', $diff / 3600, 'hours';
> 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?
$month = 2;
$year = 2000;
$number_of_days2000 = date('t', gmmktime(12, 0, 0, $month, 15, $year));
$year = 2004;
$number_of_days2004 = date('t', gmmktime(12, 0, 0, $month, 15, $year));
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Navigation:
[Reply to this message]
|