Only display hours if time is greater than 60 minutes - excel

I'm using a time-tracking sheet that calculates the time spent on a job by doing a simple subtraction between a start time and an end time in two cells.
The hh:mm format would suffice in this case, or as a small modification I'm using [h] "h" mm "m", but the issue with both is that I do not want the hours to display when there are none (when hours = 0).
If for example 35 minutes are logged I would like the output to be 35 m and not 0 h 35 m. The [mm] format might be an option then, but I would still like my time above 60 minutes to be displayed as 1 h 30 m, and not 90 m.

Please try:
[<0.04166666][mm] "m";[h] "h" mm "m"

Not at all elegant, but how about this:
=IF(HOUR(time)<1,MINUTE(time)&"m",HOUR(time)&"h "&MINUTE(time)&"m")
Returns a cell value 02:24:00 as "2h 24m"
and a cell value 00:14:24 as "14m"

Related

Excel Change "x h x m" Format into minutes only

I am Trying to change the Excel cells which contain hours and minutes with "h" and "m" into minutes only. The Problem here that the letters h & m are in the cell.
What i need it to look like:
2h 30m --> 150
4h --> 240
51m --> 51
Please help me out. thanks in advance.. !!
Try:
Formula in B1:
=1440*TEXTAFTER(":0:"&SUBSTITUTE(SUBSTITUTE(A1,"m",""),"h",":"),":",-2)
You could try something like this:
=IF(ISNUMBER(SEARCH("h";A1));VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1;" ";"");"h";":");"m";""))*24*60;VALUE(SUBSTITUTE(A1;"m";"")))
Notice there is an IF to separate cases when there is only minutes from cases when there is also hours (calculus is different)
So find the "h" to get the hours like so:
=left(A2,find("h",A2,1)-1)
Then multiply the result by 60 (as 60 minutes in an hour)
For minutes:
=mid(A2,find("h",a2,1)+1,2)
This assumes that minutes is double digit as per your example, you could make it more precise by finding the position of the "m" and calculating the difference.
Then sum the result to get minutes.
Another legacy formula:-
=1440*SUBSTITUTE(SUBSTITUTE(IF(COUNTIF(A1,"*h*"),"","0h")&A1,"h",":"),"m","")

Custom time format excel: don't display zeros if hours or minutes are zeroes

There was an question placed before and it got the answer:
Thanks for that.
"Right now I have formatted my cell with:
h "hours" m "minutes"
So if my cell has 7:00, it displays as 7 hours 0 minutes. Is there a way to remove the hours or the minutes if these are zero? Something like 7 hours, or 0:30 as 30 minutes"
The answer was:
If you have Excel 2007 or later versions (but apparently not Excel for Mac 2011) you can achieve this with a combination of regular formatting and conditional formatting.
Assuming data in A1 down use a regular custom format like this
[<0.0415][m]" minutes";h "hours" m "minutes"
That will give you the same as your previous formatting except that any value < 01:00 will display like
30 minutes
Now you can add a conditional formatting condition. With column A selected do this
Conditional Formatting > New Rule > Use a formula to determine which cells to format > type this formula in the box
=MINUTE(A1)=0
Click the "format" button and set the following number format
h" hours"
Now if you have 16:00 in A1 that will display as just 16 hours
[conditional formatting rules will always supersede regular formatting]
But I wonder if it is possible in addition to this add time format in a way like if I have 1 hour it shows "1 hour" (in singular) instead of "1 hours"?
This should do this trick
Add this to Custom type box
[<0.0415][m] "minutes";[<0.083][h] "hour" m "minutes";[h] "hours" m "minutes"
inputs/outputs
inputs -
00:05:00
00:30:00
01:05:00
01:30:00
02:30:00
outputs -
5 minutes
30 minutes
1 hour 5 minutes
1 hour 30 minutes
2 hours 30 minutes
Notes
By putting the square bracket around [h] it will allow for more than 24 hours to be added e.g. 31 hours 30 minutes.
In Excel 1 minute is equal to 0.00069444 (1/1440 of a day). Knowing this helps to calculate the two less-then numbers.
Alternative option
If you just want h rather than hour and m rather than minutes try this
[<0.0415][mm] "m";[h] "h" mm "m"
=IF(HOUR(B9)<>0,HOUR(B9)&" hour"&IF(HOUR(B9)<>1,"s "," "),"")&IF(MINUTE(B9)<>0,MINUTE(B9)&" minute"&IF(MINUTE(B9)<>1,"s",""),"")
TLDR : extract every values manually > then put if conditions for 0,1 and other > print value..
Hope it helps.

How do I calculate this time? Across midnight

I have a sheet with start and end dates and values.
In C I have start date.
In E I have end date.
In I I have start time. (06:05:00)
In J I have end time. (08:33:00)
If C <>E I need to add 24 hours to the time elapsed.
How can I do that?
I tried if(C2<>E2;1+J2-I2;"omitted")
But I get the result 21:32:00.
It should be about 26 hours
(24+8-6 = 26 if we only look at the hours).
What have I done wrong?
Edit;
Back at work and can now upload some images.
Method 1
Method 2
Both return the wrong time.
EDIT2;
Method 3
I remember how I always have to format the dates from "our" format to Excels format for it to be recognized as a date.
In column P I use RIGHT(), MID(), and LEFT() to make a correct formatted date.
In R and S I use the same as P&Q column.
Still not correct.
:-/
EDIT again:
Use formula: =(E1+J1)-(C1+I1) we just add the date and time together and subtract the end from start and then format the cell having the formula to show days, hours, minutes.
This way, if you have more than 1 day difference, you're not just adding 24 hours.
Change the format of the target cell contianing the above formula to
d "days" hh "hours" mm "minutes"
or use the format tigerAvatar suggested of [hh]:mm if you want the hours to be cumulative across days.
Then you get a nice output of: 2 days 02 hours 28 minutes or 50:28
Feel free to drop the 1 h or 1 m if you don't want the leading zeros.
A picture is worth a 1000 words so:
Version 2 after your screenshots: I don't think C, E are in date format based on your updates so...
I used formula=(DATE(LEFT(E2,4),MID(E2,5,2),RIGHT(E2,2))+J2)-(DATE(LEFT(C2,4),MID(C2,5,2),RIGHT(C2,2))+I2) in K and custom format mask: [h]:mm
If this doesn't work it may be a regional setting and the interpretation of [h]:mm I am assuming I/J are time formats.

Rounding to two specific times

I need a formula that will round to either a time 15 minutes or 45 minutes past the hour based on the minutes in a time..
Example: If I have a time in A1 and the minutes are 46 and 14, I want the formula to return the time of 15 past the hour.
If A1 has 11:47 then return 12:15.
If I have a time in A1 and the minutes are between 16 and 44, I want the formula to return the time of 45 past the hour.
If A1 has 12:23 then return a time of 12:45
Any time that is either 15 or 45 past the hour will not change.
=CEILING(A1+TIME(0,15,0),TIME(0,30,0))-TIME(0,15,0)
Add 15 minutes
Roundup to the nearest 30 minutes
Subtract 15 minutes
This is a bit complicated but... (updated)
=(CEILING((A1-(15/(24*60)))/(1/48), 1)*(1/48))+(15/(24*60))
It goes something like this:
Subtract 15m to the time
Divide by 30m
Round up this value
Multiply by 30m
Add 15m
Here is a formula using the logic from my comment above:
=IF(AND(A1>=0,A1<=15),15,(IF(AND(A1>15,A1<=45),45,15)))
Remember, you will also need to add 1 to the hour in the final case (where A1 > 45).
Here is a breakdown of the above formula:
1. If A1 is between 0-15, then it will return 15.
2. If A1 is between 16-45, then it will return 45.
3. If A1 is between 46-59, then it will return 15. (the logic to add an hour is not handled in this formula)

Excel Function For If Then Statement for Range of Times

=IF(I44<"0:01","0",IF(I44<"0:30","2:00",IF(I44<"1:00","2:30",IF(I44<"1:30","3:00",IF(I44<"2:00","3:30",IF(I44<"2:30","4:00",IF(I44<"3:00","4:30",IF(I44<"3:30","5:00",IF(I44<"4:00","5:30",IF(I44<"4:30","6:00",IF(I44<"5:00","6:30",IF(I44<"5:30","7:00",IF(I44<"6:00","7:30",IF(I44<"6:30","8:00",IF(I44<"7:00","8:30",IF(I44<"7:30","9:00",IF(I44<"8:00","9:30",IF(I44<"8:30","10:00",IF(I44<"9:00","10:30",IF(I44<"9:30","11:00",IF(I44<"10:00","11:30","")))))))))))))))))))))
(Left out the code tags so you dont have to scroll 30 pages to the right)
I am using this function to add specific amounts of time to specific range of time and this seems like there must be a better method of doing this.
For example: for a input time of < 30 min, would output 2:00 hr, for input time of < 1:00 would output 2:30 ... and for each 30 min increment in the input the output would increment by 30 minutes
Perhaps just round down to the next half hour then add 2 hours, i.e
=IF(I44=0,0,FLOOR(I44,"0:30")+"2:00")
[with an IF to deal with zero values]
Format result cell as a time value, e.g. h:mm or similar

Resources