I have duration data in text format like so:
19min 30s
I would like to convert this to hours and I need the hours to be integers. How do i do that?
I have tried to split the text but I am unable to categorise the array into hours, minutes and seconds
Try
=("0:"&textjoin(":",,REGEXEXTRACT(A1,REGEXREPLACE(A1,"(\d+)","($1)"))))*24
explanation:
The formula extracts numeric values (\d+), then join 0: the first value (minutes) : and the second value (secondes). The result is multiply by 24 to get hours.
use:
=ARRAYFORMULA(IF(A2:A="",,
IFNA(REGEXEXTRACT(A2:A, "(\d+)h")/24)+
IFNA(REGEXEXTRACT(A2:A, "(\d+)min")/24/60)+
IFNA(REGEXEXTRACT(A2:A, "(\d+)s")/24/60/60)))
Related
I hope everyone reading this is doing well. I am making attendance sheets on Google Sheets that also calculates the salary of the person. It is entirely automated except for one part, the part that calculates salaries.
For that I need to separate the Hours and Minutes worked so that I can calculate the salary accurately based on 60 minutes instead of the first half being in hours and the second from a percentage of 100.
It coverts the hours into days and omits the remaining hours. Please assist. Thank you!
What it does
What it should do
HOUR() returns the hour component of a specific time, so it will always return a value between 0 and 23.
In Google Sheets, times are just numbers where 1 indicates 1 day. So a duration of hh:mm:ss means hh/24 + mm/24/60 + ss/24/60/60 which means hours_in_a_day + minutes_in_a_day + seconds_in_a_day. (You can see this if you format the cell as "Number")
So, if you want to extract the hours from a duration, you have to multiply it by 24 and take the INT().
=INT(B20*24)
Spreadsheet time values such was elapsed hours are in units of days. In your spreadsheet, salary is recorded per hour. To multiply the hours by the salary, first convert the salary per hour to salary per day, and then multiply by the elapsed hours, like this:
=n((B23 * 24) * B20)
The n() wrapper is there just to get the number format right. You can also leave it out and format the formula cell as Format > Number > Currency.
See this answer for an explanation of how date and time values work in spreadsheets.
I am recording my time spent on a project in google excel sheet. There is a column which does addition of the recorded time and output total time to column say D40. The output time looks like <hoursspent>:<minutesspent>:<secondsspend>. For example 30:30:50 would mean that i have worked for 30 hours and 30 minutes and 50 seconds on a project.
Now, I was using this formula to calculate my total invoice
=(C41*HOUR(D40))+(C41*((Minute(D40)/60)))+(C41*((SECOND(D40)/3600)))
Where C41 cell contains my hourly rate (say $50).
This is working fine as long as the numbers of hours that i have worked are less than 24. The moment my numer of hours go above 24. The Hour function return the modulus value i.e., HOUR(30) would return 6.
How can I make this calculation generic in a way that it oculd calculate on more than 24 hours value too.
Try
=C41*D40*24
and change formet on the result as $
one hour is part of a day, as you know 1/24th of a day, that's why you could multiply by 24 to get hours, and then multiply it by the rate
Try below formula-
=SUMPRODUCT(SPLIT(D40,":"),{C41,C41/60,C41/3600})
When you store a value as HH:mm:ss into an Excel sheet, it automatically formats it as a Time, so it makes sense that HOUR modulos by 24.
Which is why you can simply ignore it. If you have a cell that is formatted as currency (FORMAT > Math > Currency) or any other normal Number-like format, then you can see, if you perform a numerical operation like multiplication, that it stores times like "30:30:50" as if it were a TIMEVALUE with a value over 1. Simply multiply that by 24, and then by your hourly rate, and you'll get your value, i.e,
=D40 * C41 * 24 :
Just replace HOUR(D40) with INT(D40)*24+HOUR(D40)
In Google Sheets, is there a way to multiply time values with currency values? Current result doesn't work.
In other words,
Multiply hours(A) * dollars(B), result display in dollars(C)
What's the syntax to write this kind of matching?
Thanks in advance!
try:
=TEXT(TIMEVALUE(B2)*B4, "$0.00")
Retrieve the total number of hours in B2 by using a combination of DAYS (for the number of full days passed, which you have to multiply by 24 to get the hours) and HOUR (for the hours passed in the last -nonfull- day):
DAYS(B2,)*24+HOUR(B2)
Then you can multiply that by B4:
=(DAYS(B2,)*24+HOUR(B2))*B4
Looks like "Hours later than 6pm" should be a number and not a time value.
I want to get an hour ago hour value of current time in google sheets.
For example
TEXT(NOW(),"DDHH")
returns current date+hour value (2500, if its 25th, midnight)
can I get 2423 instead using formula?
just putting -1 works for most of hours but fails at midnight (it returns 2499)
Try using
=TEXT(NOW()-1/24,"DDHH")
In date notation 1 is one day and one hour is 1/24 of a day.
It works for me:
(note that I use ; instead of comma as I have polish settings in my spreadsheet).
Adding -1 at the end of the formula will return 2499 because it will treat it like integer 2500 - 1. Adding -1 after NOW() will return 2400 because it will subtract 1 as 1 day. You can try this formula to subtract an hour.
=TEXT(NOW()-(1/24),"DDHH")
I have a cell formatted as a duration (6:49:00)
I want to convert that to an Integer of total seconds
This formula gives me the right number of seconds =C3*60
409:00:00 <-- But I want this as just 409
To convert duration to an integer expressing the number of seconds, use a formula such as
=value(A1*24*3600)
Time values are recorded so that 1 is one day. Multiplying by 24 (hours/day) and 3600 (seconds/hour) converts that to seconds. Then value makes it a number rather than duration.
Old answer, about formatting only.
You don't need any formulas to format duration as the number of seconds.
Go to Format > Number > More formats > More data and time formats
Delete the pre-filled format fields and add "Elapsed seconds" from the dropdown menu.
I have found this solution:
let the cell A1 filled with duration like 1:22:33, than formula
=HOUR(A1)*3600+MINUTE(A1)*60+SECOND(A1)
will do the trick.
For example, 1:01:01 -> 3661
=HOUR(A1) will NOT work if your hours in the duration is > 24 of course. So the last example is not correct.
What will work is the following.
Given: A duration in hours and minutes. eg 225:04 or 9:20 or 62:35
Format must be set as this (Elapsed hours:minutes)
=INDEX(SPLIT(A1, ":"), 0, 1)*60 + INDEX(SPLIT(A1, ":"), 0, 2)