How to convert a number into hours in Google Sheets - google-sheets

1950 minutes is 32.5 hours. How do I calculate this using a formula in Google Sheets?
I am logging the number of minutes that I take on completing tasks and need a way of converting these numbers into the number of hours in Google Spreadsheets.
I have a column that contains rows of minutes, 1 row per task. This sum total of this column then needs to be added together, then converted into hours.

Here is a function that converts minutes in hour:minutes,
=if( A1 = 0 ; "" ; concatenate( quotient( A1 ; 60 ) ; ":" ;MOD(A1 ; 60) ))
62 --> 1:2

Use convert function to convert a numeric value to a different unit of measure
=CONVERT(A1; "mn"; "hr")
Documentation

Here is a function that converts minutes in hour:minutes:
=CONVERT(A1,"mn","hr")/24
Where A1 is the section you want to convert

Add up all the values using the function =SUM(number1,number2,number3,number4,...).
Example: =SUM(A1:A200) adds up all the numbers from A1, A2, A3 ... until A200.
Divide the total number of hours (it's located in the field with the =SUM function) by 60 (60 minutes in 1 hour, of course) with =DIVIDE(number1,number2)
Example: =DIVIDE(A201,60). In case you put the =SUM function in field A201, you divide the result of that field by 60.

Pierre's answer is mostly correct. However, it does not properly output the time if the number of minutes is below 0. If you need to handle a negative time amount, use the following formula instead:
=CONCATENATE(IF(AND(A1 < 0, A1 > -60), "-", ""), QUOTIENT(A1, 60), ":", TEXT(MOD(ABS(A1), 60), "00"))

I've improved it:
123 to proper 2h 3min
Do not show insignificant 0.
not show "0 mins" (number is completely divisible by 60) e.g. 120mins to 2h and NOT 2h 0min
not show "0h" (number is less than 60) e.g. 40min to 40min and NOT 0h 40min
To use just replace A1 with the cell number of the cell that contains mins.
=IF (A1=0, "", CONCATENATE ( IF(QUOTIENT(A1,60)=0, "", CONCATENATE (QUOTIENT(A1,60),"h ") ), IF(MOD(A1,60)=0,"",CONCATENATE (TEXT(MOD(A1,60),0),"min"))))

Related

Repeating & Incrementing Dates up to a given number of week in Sheets

A1 = 6-Dec
B1 = 2
Goal: Repeat all the dates 7 times starting from 6-Dec (Value in 'A1') up to 2 weeks (Value in 'B1')
Formula Used :
=ArrayFormula(FLATTEN( split( REPT(SEQUENCE(7,1,A1,1)+SEQUENCE(1,B1,0,7)&"$",8),"$")))
Expected Result :
Two columns for two weeks. Each date of the week to be repeated 8 times.
Actual Result :
Only 1st week is repeated
Please help me in correcting the formula.
=ARRAYFORMULA(A1+TRANSPOSE(SEQUENCE(B1,7*8,0)/8))
A1: Date
B1: Weeks
SEQUENCE/TRANSPOSE to create a sequence of numbers increasing in the vertical direction
/8 Divide by 8 to create 8 fractional numbers for the same number.
Add the fractional numbers to the date A1 to create a date sequence repeated 8 times
FLOOR[optional] the fractional numbers, if exact dates are needed without time difference.
use:
=INDEX(TEXT(FLATTEN(TEXT(SEQUENCE(7, 1, A1), SEQUENCE(1, 8,,))),
SEQUENCE(1, B1,,))+SEQUENCE(1, B1,, 7))

In sheets is it possible to convert a duration formatted as a string into the number of minutes?

I am trying to convert a duration to a number. I have a cell that lists total hours and total minutes from a Google Meet. I am trying to automatically convert that information to the total number of minutes expressed as a number.
Ex: Cell 1(1 hr 8 min) to Cell 2 (68)
The google meet data, with the total hour/ total minutes) will be automatically pasted in from the meet report.
Is this possible?
If you have the duration always expressed as X hr Y min,
UPDATED:
= ARRAYFORMULA(
IFNA(
IF(LEN(B2:B),
REGEXEXTRACT(B2:B, "\d+") * 60 + REGEXEXTRACT(B2:B, "\D+(.+)min"),
""),
REGEXEXTRACT(B2:B, "\d+")
)
)
This part extracts the number before the hr and we multiply it by 60
REGEXEXTRACT(B2:B, "\d+")*60
This part extracts the number between hr and min and we add it to the above result:
REGEXEXTRACT(B2:B, "\D+(.+)min")
To adapt the formula to your situation, please consider the following notes:
Durations in the example starts from B2
Total is retrieved in C2:C
Arrayformula is used: i.e. only one formula is used in C2, and no need to copy the formula down
Supposing your original string were in A2, and that no meeting ran more than 9 hr 59 min, you could use this simple approach:
=TIME(LEFT(A2,1),MID(A2,6,2),0)*24*60
ADDENDUM (after more information added by poster)
This will cover your newly given scenarios:
=TIME(IFERROR(REGEXEXTRACT(A2,"(\d+) hr"),0),REGEXEXTRACT(A2,"(\d+) min"),0)*24*60

Calculating total daily time in a spreadsheet with time ranges per cell

I have a basic spreadsheet to keep track of time spent on an activity.
The idea is to capture a time range per cell. E.g. 10:00 - 12:30 means 2 hours and 30 minutes.
Breaks can be taken during the day. On resuming, a new time range is entered in a new cell.
I want to calculate the total time per day. E.g. Mon Jun 15 is 2.5 + 4.5 = 7 hours.
The algorithm I'm thinking of is more or less
for each cell that contains time ranges for the given day
start, end = split(cell, " - ")
diff_decimal = (end - start) * 24
total += diff_decimal
But I'm not sure how to do this with spreadsheet functions.
The starting point I have is using =SPLIT(B2," - ") but I'm already blocked since I'm not sure how to handle the return value.
P.S. The problem could be simplified by having multiple "start" and "end" columns with one value per cell. But I want to try the given format, which I prefer, before trying another approach.
This is Google Sheets solution, as Excel does not have regex formulas.
Try this formula (place it in G1, column G:G formatted as number):
={
"Total";
ARRAYFORMULA(
IF(
A2:A = "",
"",
MMULT(
IFERROR(
( TIMEVALUE(REGEXEXTRACT(B2:F, "-\s+(\S+)"))
- TIMEVALUE(REGEXEXTRACT(B2:F, "(\S+)\s+-"))) * 24,
0
),
SEQUENCE(COLUMNS(B2:F), 1, 1, 0)
)
)
)
}
If you format G:G as Duration then you can remove * 24 part.
UPD
Added ignoring of the wrong formatted cells with IFERROR - just 0 in this case.
Better add this custom conditional formatting rule for B2:F to mark (in red on the screenshot) time periods in the wrong format and go fix them:
=AND(B2 <> "", NOT(IFERROR(REGEXMATCH(B2, "\b(\d|[01]\d|2[0-3]):[0-5]\d\s*-\s*(\d|[01]\d|2[0-3]):[0-5]\d\b"), False)))

Sum values for the same date in google spreadsheet

I have a google spreadsheet that's tracking the duration of a particular activity over time. Imagine it looks something like this:
date | start time | end time | duration
5/21/18 10:00 AM 10:30AM 30
5/21/18 11:30 AM 12:30PM 60
5/21/18 2:00 PM 2:30PM 30
5/23/18 11:30 AM 12:30PM 60
5/24/18 9:30 AM 11:30AM 120
I want to make a chart with the dates along the X axis and the duration along the Y axis. However, I want each date to just be shown ONCE, with the TOTAL SUM duration for that date. So, the bar for 5/21/18 should be 120 min (i.e. the total of the three 5/21/18 entries), the bar for 5/22 should be 0 minutes (since there is no entry), and the bar for 5/23 should be 60 min.
If I make a chart as is, it treats each row as a separate entry (so there are three separate bars for each of the 5/21/18 entries), which doesn't work for my purposes since I want to combine entries with the same date, and have entries for in-between dates that have no entries.
Thank you!
You need to add any missing dates in the series.
In this case there is only one day but it could just as easily be two, three or a month's worth of dates.
Credit for missing dates in series: "--Hyde", Google Docs Help Forum Automatically Insert Missing Rows And Fill Values.
Assumption: the range shown in the question starts in cell A1 on a sheet named 'so_53684341'.
1) Create a new data series, including any missing values
a) Create a new sheet.
b) Cell A1, insert =arrayformula( { "Date"; datevalue("21/05/2018") + row(1:4) - 1 } ).
c) Cell B1, insert =arrayformula( {"Start time","End time","Duration"; if( len(A2:A), iferror( vlookup( A2:A, {datevalue(left(substitute(so_53684341!A2:A, " ", "-"), 10 ) ), so_53684341!B2:D }, column(so_53684341!B2:D2), false ), { "", "", 0 } ), iferror(1/0) ) } )
This creates data in columns B, C and D. It duplicates the existing data on the original range. and puts a zero value in the Duration column for any non-existing date(s).
You can format the date column as appropriate.
2) Create a query to be used as the basis for the chart
a) Cell F1, insert =query(A2:D5,"Select A, sum(D) group by A label (A) 'Date', sum(D) 'Duration' ")
This creates a range F1:G5
3) Create a chart using the range F1:G5
Something like this

Repeating time windows in Google Spreadsheets?

I'd like to insert time windows repeatedly in a column, like this:
10:00-10:20
10:20-10:40
10:40-11:00
11:00-11:20
11:20-11:40
12:00-12:20
Is there a way to achieve this?
Put data in cells:
B1 = 10:00 (start time)
B2 = 12:20 (end time)
B3 = 20 (interval in minutes)
Here's single arrayFormula, that will generate your column:
=ARRAYFORMULA(TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)-1),"HH:MM")&"-"&TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)),"HH:MM"))
Explanations
Look at sample file to explore more about this formula. Pay attention on some details:
any kind of logical sequence could be done with help of series 1,2,3... Formula like =ARRAYFORMULA(row(OFFSET(B8,,,7))-row(B7)) gives us column from 1 to 7.
Time treated like numbers in sheets: 1 day is 1, 1 hour is 1/24, 1 minute is 1/24/60 and so on
Time can't be properly converted into text as it's number. So you have to use text(time, "HH:MM") formula to convert time into text.
This will repeat your time window. The formula assumes the time range is in A2:A6.
The 3 in the formula is the number of repeats (change to you need). You might want
to consider placing A2:A6 on another sheet and referencing it in the formula.
=TRANSPOSE(SPLIT(JOIN(",", ARRAYFORMULA(SPLIT(transpose(rept(join(",",A2:A6)&",",3)),",")&",")), ","))

Resources