Convert hours to months-days-hours

Solved
akaisii Posted messages 150 Status Membre -  
akaisii Posted messages 150 Status Membre -
Hello,

I want to convert a number of hours into months-days-hours, and have the result in one cell.
I found some things about the subject on forums but it doesn’t work in my case, that is, when the number of months is less than 1.
For example, 600h and taking as a base, 1d = 24h
It should give 0 months 25 Days 10 Hours.

If anyone has an idea please.
Thank you in advance,

6 réponses

Benoit A. Posted messages 455 Registration date   Status Membre Last intervention   515
 
600 hours does not equal 25 days and 10 hours!! It just makes 25 days.
600 / 24 = 25 !!
For months it's more complicated because the number of days varies from month to month. From what I can say, there should be a correspondence table that gives you the number of days per month. But even then, I'm not sure it would work.

In the meantime, here’s how to calculate the number of days and hours:

=ROUNDDOWN(A1/24;0) &" Days " & ((A1/24) - ROUNDDOWN((A1/24);0)) * 24 &" Hours "

I don’t know if that works for you.
4
michel_m Posted messages 18903 Registration date   Status Contributeur Last intervention   3 320
 
Hello
a little problem:
there are months with 30 days, 31, 28, 29....,
what do we do?

--
Michel
0
michel_m Posted messages 18903 Registration date   Status Contributeur Last intervention   3 320
 
Hello
in cell A1 use the format hh:mm:ss
for example
600:00:00
(equivalent to the date of 25/01/1900 00:00:00)
this formula
=(MONTH(A1)-1)" months "&DAY(A1)" day(s) "&HOUR(A1)" hour(s)."
will return
0 months 25 days() 0 hour(s)

3457:00:00 (23/05/1900 01:00:00)
will return
4 months 23 days 1 hour
so it may be off by 1 or 2 months depending on the number of days/months
Michel
0
akaisii Posted messages 150 Status Membre 41
 
Thank you for your answers.
My apologies. In my example, I meant 610 hours.
To generalize for now, I'm basing this on 1 month = 30 days.

Benoit A. > This formula does not give months if the number of days exceeds 30 days.
For example: 800 hours gives 33 days 8.00000000000006 hours, instead of 2 months and 2 days 8 hours.

michel_m > Indeed, it works for this example but it is not generalizable because in other cases it gives inaccurate values.
For example: 5000 hours gives 6 months 26 days 8 hours, instead of 7 months and 26 days 8 hours.

Otherwise, what I've done so far is to apply the cell formatting mm "months and" jj "days" h "hours" and it works partially, and the problem is that there shouldn't be less than 30 days.
0
michel_m Posted messages 18903 Registration date   Status Contributeur Last intervention   3 320
 
As I wrote to you at the start, since WE DO NOT KNOW THE DATE, no matter what formulas or VBA functions are used, the result will ALWAYS BE RANDOM and THEREFORE NOT RELIABLE.
It is therefore the design that needs to be reconsidered.
Good luck :o)
Best regards.
0
akaisii Posted messages 150 Status Membre 41
 
Thank you, michel_m.
In fact, what needs to be taken into account in my current needs is the quantitative volume of the duration but not the date or period.
0
eriiic Posted messages 24581 Registration date   Status Contributeur Last intervention   7 281
 
Hello,

michel_m > Indeed, it works for this example, but it's not generalizable because in other cases it gives inaccurate values.
For example: 5000 hours gives 6 months, 26 days, 8 hours, instead of 7 months and 26 days, 8 hours.

You're not consistent with yourself.
Earlier you said 1 month = 30 days of 24 hours
With 5000/24/30 = 6.9444.
How can you find 7 months and 26 days???

The same goes for 800 hours. 800/24/30 = 1.111
How do you expect to find 2 months and 2 days?

eric

--
By continuously trying, we eventually succeed.
So the more it fails, the more chances we have that it will work. (the Shadoks)
In addition to the thank you (yes, really, it’s done!!!), remember to mark it as resolved. Thank you.
0
akaisii Posted messages 150 Status Membre 41
 
Thank you eriiic.
Thanks to you, I realize that what I have is indeed random too :(
5000h gives 6 months 28 days 8 hours.
800h gives 1 month 3 days 8 hours

Does anyone have an idea please?
0
eriiic Posted messages 24581 Registration date   Status Contributeur Last intervention   7 281
 
How are your hours recorded?
5000 or 5000:00?
0
akaisii Posted messages 150 Status Membre 41
 
5000 but I can review the entry if necessary.
0
eriiic Posted messages 24581 Registration date   Status Contributeur Last intervention   7 281
 
Hello,

=INT(A2/24/30)" months "&INT(MOD(A2/24;30))" days "&MOD(A2;24)" hours"

eric

By continuously trying, you eventually succeed.
So the more it fails, the more chances you have that it works. (the Shadoks)
In addition to thank you (yes, it can be done !!!), remember to mark as resolved. Thank you.
0
akaisii Posted messages 150 Status Membre 41
 
It works perfectly, thanks Eric ;)

Now I'm wondering if it works every time or if it's also random?
0
eriiic Posted messages 24581 Registration date   Status Contributeur Last intervention   7 281
 
Yes, of course, it's random. Sometimes it's good, sometimes it's not. It depends on Excel's mood... ;-)
Any other questions like that?
eric
0
akaisii Posted messages 150 Status Membre 41
 
:D
Thank you again, Eric ;)
0