📜 ⬆️ ⬇️

Does every day have 24 hours?

Today I came across a function that should calculate the number of days between dates, inside it something like this was written:

$arr_mk = mktime (0, 0, 0, date('m', strtotime($arr_date)), date('d', strtotime($arr_date)), date('Y', strtotime($arr_date)));
$dep_mk = mktime (0, 0, 0, date('m', strtotime($dep_date)), date('d', strtotime($dep_date)), date('Y', strtotime($dep_date)));

$mk_diff = $dep_mk - $arr_mk;
$days = bcdiv($mk_diff/86400); // 60*60*24

It seems everything is true at first glance, but she worked suspiciously.

Googling found a similar code on phpclub.
And the problem is this:
the difference between '27 -03-2009 'and '30 -03-2009' is 2 days.
the difference between '27 -04-2009 'and '30 -04-2009' is 3 days.
Suspiciously, I thought the podglyuchivaet already at the end of the day, en-no. Taki wrong.
And the whole problem is this.
March 29, at 23:00, due to the transfer of time, the total was not 3, but 2.95 and bcdiv issued 2.
Similarly, I thought that at 25 October at 25 o'clock - the way it is.
This is how it happens, nobody can be trusted :)

')

Source: https://habr.com/ru/post/55525/


All Articles