Convert hours to nY nM nD?

Tags: #<Tag:0x00007faee0967058>

I’m trying to achieve same results as from simple php function which converts hours into readable format of years/months/days

$hours = 22236;
$days = round($hours / 24);
$end_date = new DateTime(date("Y/m/d",strtotime("+$days days")));
$start_date = new DateTime(date("Y/m/d"));
$dd = date_diff($start_date,$end_date);
echo $dd->y."y ".$dd->m."m ".$dd->d."d";

which will print
2y 6m 12d

I’m not yet deeply familiar with simpledateformat so I need bit of help if that can be done by that function or somehow differently.

Thanks for hints!

If you are looking at simpledateformat you are looking in the wrong place. A DateTime represents an instant in time, not a duration.

There is no built in function to format a duration. You need to write a rule or JavaScript transform to convert a Number of minutes or seconds to the String format you are after.

well it basically works with dates as it counts today + n and then differs (which i can handle) What I’m really looking for is how to convert hours into

today + hours = datetime (eq. equivalent of strtotime)
and then I’ll move on with a rule


thanks! :+1: