I am comparing a date with a datetime and I get the result I expect however I also am wondering if there is a better way to display my output and I have a query on my current output also.
Here is a snippet of my current code:
<?php $todayDate = date('Y-m-d'); $seconds = strtotime($todayDate) - strtotime($dueDate); $hours = $seconds / 60 / 60; echo number_format($hours, 2); ?> in my case $dueDate in my database here is 2017-06-26 09:11:28 so the output is displaying as -57.19. My question, is there is a clean way to strip the - and also add h after the hours and m after the minutes so the output looks like this?
57h 19m
UPDATE
So After tinkering around I have managed to do this:
substr($dateFormat,0,3).'h '.substr($dateFormat,4).'m';
The output now is -57h 19m
I still have this negative character, im not sure if that is actually correct I cannot seem to work it out because the date in my database is a day ahead but it shows a negative value...
.19is not 19 minutes, it is 11.4 minutes..19 * 60.$dueDatewith your query then let the DB do the math... or if with the math the decimal part is from a piece of 60, not 100.