I need to express a past date to now difference in a human readable format (e.g. 1day 2hours 1minute etc..).
Here my try:
<?php
function datediff($datatodiff){
$date = new DateTime(date("Y-m-d G:i:s", $datatodiff/1000))
$now = new DateTime();
$interval = $date->diff($now);
return $interval->format("%m month %d days %h hours and %i minuts");
}
?>
My problem is that if I have to split the date in hours and minutes, I want to see all the time interval expressed.
My attempt is working, but only if i show all time units. I can clarify with an example.
1 year 4 months 3 days 1 hour 2 minutes
if i remove the months the output is 1 year 3 days 1 hour 2 minutes
but i'd like:
1 year 123 days 1 hour 2 minutes
. This behaviour with all units
The time units that will be displayed are chosen by the user. I also tried Carbon lib without success.
In Android I use period formatter from JodaTime Lib if can help.
Thank you in advance.