Total hours of overtime - google-sheets

I keep a google spreadsheet where I enter hours worked per day. I'm supposed to work 8 hours per day and anything more than that is overtime.
So I need to check if a value in the column with hours is greater than 8. If so I want the difference between 8 and the value entered, added to or accumulated in another cell so that I can see how many hours of overtime I have worked. Also if the value is less than 8 then I need to make a deduction.
Can anyone help me with such a formula?

Let's say your hours are entered in column B, and start on row 2. In a column further along, put the following formula:
=if(B2>8,B2-8,0)
This first checks whether that day have any overtime =if(B2>8 - if it does, it calculates how much B2-8 - if it doesn't, it shows 0 instead.
Then, underneath that column, you can sum for your answer. It will look something like this.
A | B | C
Day | Hours | Overtime
------------------------------
Monday | 8 | =if(B2>8,B2-8,0)
Tuesday | 9 | =if(B3>8,B3-8,0)
Wednesday | 9 | =if(B4>8,B4-8,0)
Thursday | 8 | =if(B5>8,B5-8,0)
Friday | 10 | =if(B6>8,B6-8,0)
------------------------------
Total | Total | =SUM(C2:C6)

Related

Google Sheets duration between 2 timestamps where the ending timestamp crosses into midnight

I have a sheet where I'm calculating the durations of time between two timestamps.
As an example, I have column A, which is the starting time, and column B, which is the stopping time. Both A and B are formatted as Time. Column C holds the duration between A and B, and is formatted as Duration.
The formula =SUM(B1 - A1) works fine for the most part, until I reach a situation in which B1 has crossed into midnight of the next day
For example if I have the following:
A | B | C
------------------------------
23:30 | 23:40 | 0:10:00
23:30 | 23:50 | 0:20:00
23:30 | 00:00 | -23:30:00
23:30 | 00:10 | -23:20:00
How do I circumvent this issue and have C3 & C4 properly calculate the value to be 0:30:00 and 0:40:00 respectively? My timestamps don't include date-related information, columns A and B only hold HH:MM:SS times. These durations will also never be longer than a maximum of 3 hours, so there's no need to worry about it correctly detecting overflow situations like Day 1 12:00:00 -> Day 2: 12:00:00 = 24:00:00
For mixed duration that crossed midnight of the next day (overlaps midnight)
try either of the following formulas.
=ArrayFormula(IF(A42:A="",,MOD(B42:B-A42:A, 1)))
OR
=ArrayFormula(IF(LEN(A42:A)<>0,
IF(B42:B55<A42:A,B42:B-A42:A+1,B42:B-A42:A),""))
Please adjust ranges to your needs
If you format the result column as Time, you don't need to change anything. If not, here is another option:
=B2-A2+(B2<A2)
Edit
An attempt with an array formulas:
First two results formatted as Time, last as Duration

Time differance "in mins" using current date and time stamp

How do I work out the duration from the current date and time to cell A1
A B Results
+-----------------+-------------------------------------------------------+--------------+
1 |20-01-07 07:27:27|=TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()))-C2 | 5:31:57 |
+-----------------+-------------------------------------------------------+--------------+
2 |20-01-07 07:27:27|=TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()))-C2*1440 | -56307326.9 |
+-----------------+-------------------------------------------------------+--------------+
I have tried this method above but it seems to not use the DATE.
Is there a way I can get it to include the date and also get it to display in minutes
https://docs.google.com/spreadsheets/d/15EqEkdzcPntTV1K0EfOW_BPcq7zFDNqOMNwEFdQuDIE/edit#gid=0
use:
=ARRAYFORMULA(IF(A2:A, TEXT(NOW()-A2:A, "[m]")*1, ))
=now() - A1 will give you the number of days between the date in A1 and now.
The decimal part of the number if a fraction of a day.
So if you need minutes, try the formula :
=(now()-A1)*(24*60)
The output will most likely have decimal places which is the number of seconds as fractional minutes.

Formula To Calculate Accrued Quarterly Allowance Based On Employment Length

Employees get a specified amount of allowance for each quarter of the year, which accrues as the year progresses, and resets each new year. The amount they get each quarter is determined by how long they have been employed.
YEARS EMPLOYED | $ PER QUARTER
<1 | $0
>=1 | $37.5
>=3 | $66.66
>=5 | $100
Using only one reference cell (the hire date in Cell O1), I'm trying to figure out how to put a formula together which would display the sum of all quarterly amounts accrued this year to date.
The part that is giving me trouble is that when the amount per quarter changes during the year (due to the number of years employed reaching the next level), any previous quarters for the year need to remain at their previously assigned amounts, for example:
If the HIRE DATE is April 16, 2015:
QUARTER | YEARS HIRED | QUARTERLY ALLOWANCE
Q1 | 2.71 | $37.5
Q2 | 2.96 | $37.5
Q3 | 3.21 | $66.66
Q4 | 3.46 | $66.66
If TODAY'S DATE is May 21, 2018, the total allowance amount to date = $75 (Q1+Q2)
If TODAY'S DATE is Oct 7, 2018, the total allowance amount to date = $208.32 (Q1+Q2+Q3+Q4)
How can this be done with one formula, using only the hire date in Cell O1?
I think the easiest way to get the number of complete years hired is to use Datedif:
=DATEDIF(O$1,DATE(YEAR(P$1),RIGHT(A2)*3-2,1),"Y")
placed in (say) E2, where the current date is in P1 and the list of quarters starts in A2
Then a lookup to get the allowance calculated on the first day of each quarter:
=LOOKUP(E2,{0,1,3,5},{0,37.5,66.66,100})
and finally a check to see if the first day of the quarter is on or before the current date:
=P1>=DATE(YEAR(P1),MONTH(RIGHT(A2)*3-2),1)
Then you could get the total from
=SUMPRODUCT(F2:F5*G2:G5)
Or you could combine all this into one big array-type formula:
=SUMPRODUCT((P1>=DATE(YEAR(P1),{1,4,7,10},1))*LOOKUP(DATEDIF(O1,DATE(YEAR(P1),{1,4,7,10},1),"Y"),{0,1,3,5},{0,37.5,66.66,100}))

Rails finder method that finds an entity that is just more than 24 hours away?

I'm using Rails 5 and PostgreSQL 9.5. I have a table with the following columns .
cindex=# \d crypto_index_values;
Table "public.crypto_index_values"
Column | Type | Modifiers
------------+-----------------------------+------------------------------------------------------------------
id | integer | not null default nextval('crypto_index_values_id_seq'::regclass)
value | double precision |
index_date | timestamp without time zone | not null
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
Given a point in time (say "2017-07-29 11:10") stored in a variable "my_date", how would I write a Rails finder query that returns a single Rails entry that returns the row with the smallest "index_date" that was also at least 24 hours away from "my_date"? So if I had this table data
14 | 133.951211424387 | 2017-07-31 19:10:03.235566 | 2017-07-29 19:10:03.267727 | 2017-07-31 19:10:03.267727
15 | 133.951211424387 | 2017-07-31 19:20:03.59569 | 2017-07-28 19:20:03.629418 | 2017-07-31 19:20:03.629418
16 | 139.104155235946 | 2017-07-31 19:30:08.037045 | 2017-07-31 19:30:08.04715 | 2017-07-31 19:30:08.04715
and given my example, I would expect the query to return the row with id "15" because the row with id "14" is not 24 hours away from my example. Normally this kind of query would work
CryptoIndexValue.where('index_date = ?', my_date - 1)
but since there isn't an entry exactly 24 hours away, it doesn't.
I don't think your example values quite work -- at least I don't see how you would choose that value from the table with that index date, subtracting a day. Do you mean "the row with the earliest date which is also at least 1 day in the future from my_date"?
CryptoIndexValue.
where('index_date > ?', my_date + 1.days).
order(:my_date, :id).
take
I added :id to the order by in case you need a tie-break on two rows that have the same index_date, but remove it if that's impossible due to a constraint.
Maybe you mean to subtract one day instead of adding, though.
You should use > operator combined with order.
CryptoIndexValue.order(:index_date).find_by('index_date > ?', DateTime.now - 24.hours)

Calculate working time subtracting lunch time if needed

I'm struggled with a spreadsheet that contains how much time I have been working. I have in each row the start time and end time of each working day.
Example sheet:
| | A | B | C |
----------------------------------------------
|1 |Start time |End time|Total time |
|2 |7:00 |13:30 |6:00 |
|3 |7:00 |10:00 |3:00 |
Shared table
The issue is that the total time should not consider lunch time. I want to set up a sheet that will automatically take out the half hour for lunch when the total time is greater than 4 hours. For example, if the start time is 7:00 and the end time is 13:30, I want to get 13:30-7:00 that is 6:30 minus 0:30=6:00. However, if the start time is 7:00 and the end time is 10:00, I want to get 10:00-7:00, that is 3:00. I tried =SUM(-(A2-B2)*24) but without success.
The expected output is in red. I want to obtain such output using formulas.
Thank you!!!!
Formula to be dragged down:
=mod(B2-A2;1)-if(mod(B2-A2;1)>time(4;0;0); time(0;30;0); 0)
Because of the mod() function this formula should deal with 'negative' hours in case of overnight time.
Or in arrayformula:
=ArrayFormula(if(len(B2:B); mod(B2:B-A2:A;1) - if(mod(B2:B-A2:A;1)>time(4;0;0); time(0;30;0); 0);))
Format the output column as 'duration'...

Resources