How to calculate two hours out of two?
<?php echo strtotime('7:00 pm')-strtotime('10:00 am');?>
Get the difference between labels
EDIT
echo (strtotime ('07: 00 pm ') - strtotime ('10: 00 am')) / (60 * 60); // displays 9
60 * 60 = 1 Hrs
EDIT
$fromTime = '3:00 pm';
$toTime = '12:00 am';
$timediff = (strtotime($toTime)-strtotime($fromTime))/(60*60);
echo $timediff >= 0 ? $timediff : (24 + $timediff);
source to share
I assume you can get information about am
or pm
! With this information you can do if()
to make it correct!
if()
it's PM, add 12 hours, if it's not PM, do nothing.
Do this with the times you are comparing:
if (pm==1){ time+=12; }
so it 10:00 am = false
will be 10:00 and it 7:00 pm = true
will be 19:00
19:00 - 10:00 = 9 hours = win
...
source to share
Use DateTime interface, its simple
$day1= new DateTime("today 01:33:26am");
$dayd2= new DateTime("today 10:40:36pm"); //Output: Hours: 21
$interval= $day1->diff($day2);
$h = ($interval->days * 24) + $interval->h;
echo "Hours: ".$h
Here h = number of hours. $ interval-> days means how many days are derived from the difference if we get one (1) day then add 1 * 24 (hours) = 24 + 21 = 46 hours, but here day1 and day2 contains today so that means 0 * 24 = 0 + 21 = 21
Final withdrawal: 21 hours
source to share