I have used formula "=TEXT( NOW() , "HH:mm" )" for the current time of the day.
What formula can I use to calculate the time that is left till the end of the day, 12am?
Say the current time now is 7:12pm. I would like to have a formula that would be able to calculate that I only have 4:48 hours left till 12am.
Try =TEXT(1 - NOW()), "HH:mm").
Use TIMEVALUE
https://support.google.com/docs/answer/3267350
Which returns the fraction of a day that a time represents. So you can chain it with NOW.
=TIMEVALUE(NOW())
Would return 0.5 if it was midday.
So then you can
= 1 - TIMEVALUE(NOW())
To get the amount of time left in the day expressed as a fraction.
Then you wrap it in your TEXT function to get it in hours and minutes.
=TEXT(1-TIMEVALUE(NOW()), "HH:ss")
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)
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")
Ok, so what I'm trying to do is for each month count the number of workdays, minus public holidays.
B2 -- the current year
E2:E13 -- the first day of each month
F2:F13 -- the amount of days (workday or otherwise) in that month, that year
G2:G13 -- the amount of WORK days in that month (i.e. the formula I'm trying ot write)
A8:A -- the public holidays
I can take these and create a formula (here for G2)
=NETWORKDAYS(CONCATENATE("1.",MONTH(E2),".",$B$2),CONCATENATE(F2,".",MONTH(E2),".",$B$2), $A$8:A)
(which leverages the date format dd.mm.yyyy)
The problem with that is that some of these holidays are only half a day off, whereas this formula will give people the full day off.
So an approach could be to simply add half a day back in for every half day off that was wrongfully counted as a full day off, that month.
Assuming I have
C8:C -- is the holiday in the A cell of the same row a half-day?
That turns our formula into
=NETWORKDAYS(CONCATENATE("1.",MONTH(E2),".",$B$2),CONCATENATE(F2,".",MONTH(E2),".",$B$2), $A$8:A)+COUNTIFS($A$8:A,">"&EOMONTH(E2,-1),$A$8:A,"<"&EOMONTH(E2,0)+1,$C$8:C,TRUE)*0.5
(EDIT: example sheet)
But now here's the problem: that holiday may fall on a weekend.
So if a holiday that happens to be half a day off accidentally lies on a Sunday, say, we've just wrongfully added an extra half day of work.
What I need is an additional condition that will evaluate to "true" iff the holiday date is a workday, something along
[...]+COUNTIFS([...], $A$8:A, NETWORKDAYS(ROW,ROW) > 0)*0.5
I have no idea how to reference the row like that, though.
The easy way out would be a helper column that would calculate this boolean for me, but that's ugly as unlike the 'half-day' column, we do not want the user to be able to modify these values so having them see the column will just confuse them.)
How do I write the condition in the countifs?
I have found a simple solution without using countifs. The result you are looking for is the sum of three values:
Result = Working days in a month - Full holidays days - Half holidays days * 0.5
To do this, we will start by calculating the workdays in a month, the workdays minus full holidays and the workdays minus half holidays
WD: =NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(CONCATENATE(F5,".",MONTH(E5),".",$B$2))
WD_FULL_H :=NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(F5,".",MONTH(E5),".",$B$2), filter(A8:A,C8:C=FALSE)))
WD_HALF_H: =NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(F5,".",MONTH(E5),".",$B$2), filter(A8:A,C8:C=TRUE)).
In this way we make sure that any vacation that coincides with a public holiday does not alter the final result. Next, we calculate the final working days. To do this we need to get how many full and half holidays we have in the month, which we get by subtracting the number of working days in the month:
FINAL WD: WD - (WD - WD_FULL_H) - (WD - WD_HALF_H) * 0.5
Simplifying:
FINAL WD: WD_FULL_H - (WD - WD_HALF_H) * 0.5
Finally, without auxiliary calculations:
FINAL WD:
=NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2),
filter(A8:A,C8:C=FALSE))
-
(NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2)))
-
NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2),
filter(A8:A,C8:C=TRUE)))
*0.5
UPDATED FORMULA:
I think this should do it. though there are probably other, maybe even tidier ways.
It adds back in half days if it finds matches in a FILTER().
=ARRAYFORMULA(NETWORKDAYS(E2,EOMONTH(E2,0),A$8:A$18)+IFERROR(FILTER(C$8:C$18,EOMONTH(A$8:A$18,0)=EOMONTH(E2,0),C$8:C$18,WEEKDAY(A8:A18,2<6))/2))
Time started time end Duration
6:02:53 PM 6:11:07 PM 0:08:13
6:11:22 PM 6:20:33 PM 0:09:11
6:20:48 PM 6:32:21 PM 0:11:34
6:32:44 PM 6:39:04 PM 0:06:20
6:39:28 PM 7:00:41 PM 0:21:13
7:01:00 PM 7:09:16 PM 0:08:16
7:09:40 PM 7:16:03 PM 0:06:23
7:16:03 PM 7:24:21 PM 0:08:17
7:24:45 PM 7:30:57 PM 0:06:12
7:31:27 PM 7:37:21 PM 0:05:54
7:37:21 PM 7:44:06 PM 0:06:45
I want sum of all duration entries in x hours x minutes x seconds like i have more then 1000 rows of duration when i try to use =SUM(C2:C100) I am not getting sum of total duration after sum of 24:00:00 24 hours it starts from 00:00:00
for example sum of total duration gets 24:00:00 between range of c1:c8 it will start from 00:00:00 from c9: next range kindly assist me how to overcome this issue
try:
=ARRAYFORMULA(TEXT(SUM(IFERROR(TIMEVALUE(C:C))), "[h]:mm:ss"))
spreadsheet demo
Wherever you put the =SUM(), Select that cell and do Format>Number>More Formats>Custom Number formatting, and put the same formatting that Player0 put in his answer:
What worked for me to resolve a similar problem was a suggestion by user ttarchala in Google Sheets Query multi condition sum of time duration.
I used N() function as he said, and my final formula for the duration is:
=IF(To<>"", N(To-From+(To<From))*24, "")
with To and From being Named ranges for End Time and Start Time respectively.
N() function converts the time delta into a number. Multiplied by 24, this gives the hours in decimal format, such as 2 hours 30 minutes = 2.5 hours.
From there on, there is no problem with using the built-in Sum function to calculate the total duration as a decimal. Such as, the total duration of 27 hrs 10 minutes is shown as 27.16. This sufficed for my purposes.
Time delta is calculated using a formula from https://webapps.stackexchange.com/questions/104829/calculate-time-difference-between-times-past-midnight to take into account past-midnight differences.
And the first condition, To<>"", makes sure the formula is not showing in empty cells. As soon as the End Time is filled into "To" column, the decimal duration is calculated. Then it can be used in the regular Sum function.
This seemed shorter and easier than the formulas suggested above so I am sharing it in the hopes it may help someone else. Using thus formula, I just added up the Sum of time I spent looking for this solution: 3.34 hours :)
It's a formatting problem. You formatted your reply as HH:MM:SS, therefore the number displayed is not showing the date, which would have been incremented by one. If you multiply your sum by 24, and then format the result as a pure number, you will get a number that goes above 24, and will show you the number of hours, and its decimals. If you use those hours in further calculations, the result will be correct.
In cell C1, use the formula
=IF((B1-A1)>=0, B1-A1, 1+B1-A1)
Explanation: the problem is durations that exceed the 24 hour limit, as you say.
Google Sheets has become a bit deceptive here, as it will show the correct duration for the individual time interval, but if you SUM over it, it will actually deduct the value!
A B C
23:39 1:10 1:31
When you SUM then Google Sheets will see the value in cell C1 as if it was the beginning of the same day as the time in A1. So when you in C1 do =B1-A1 then it will register as a negative duration! But it won't show up as that!
In C1 use this formula, =IF((B1-A1)>=0, B1-A1, 1+B1-A1) for individual cells in column C, when you see that cells in column B has exceeded the 24-hour limit once. The duration in C1 should still show 1:31, but now the result when doing SUM over a range of cells in column C, like =SUM(C1:C2), will now show the correct and strictly additive sum. You can safely copy this formula to all cells in column C.
PS: cells in all of the columns can have Automatic or no formatting (which I think defaults to Automatic), if your time inputs look like the above. So you don't need to format all of those cells to Time or Duration. BUT remember to format the SUM cell to Format -> Number -> Duration.
PPS: if you are manually inputting the times (for for instance time tracking), then the easiest way to keep the much simpler =B1-A1 formula is to split the time up into two rows, like this:
A B C
23:39 0:00 0:21
0:00 1:10 1:10
Then the SUM of cells in column C still becomes 1:31.