How to convert date to hours

I have:

hours1 : 403440

and date2 as :2016/01/10

I need to convert date2 to hours and find the difference between the two, which should again be in the clock.

+4
source share
2 answers

The second parameter dateis the unix timestamp, which is in seconds, so the number of your hours is 3600 (3600 seconds per hour).

$hours1 = 403440 * 3600;
$date1 = date("d-m-Y H:i:s", $hours1);
echo $date1;

Output:

09-01-2016 19:00:00

For updating your code should be:

$date2 = strtotime('2016/01/10');//get date to seconds from 1970
$hours1 = 403440 * 3600; // convert from hours to seconds
echo ($date2 - $hours1)/3600;//subtract seconds then divide by 3600 to get how many hours difference is

Output:

5
+1
source

date() - unix, 1 1970 00:00:00 UTC. , $hours1 - 1 1970 00:00:00 UTC,   date("d-m-Y H:i:s",$hours1*3600); .

, $hours2=(strtotime($date2)/3600); 1 1970 00:00:00 UTC.

0

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


All Articles