Update: How to calculate date and time duration into Days in google shee? (excluding Sunday) - google-sheets

I know it's basic but I'm new to this. I just want to know how can I calculate the days duration of the two dates?
For example, I have my start date and time 11/22/2021 15:20:43 and end date and time 11/23/2021 14:51:29 I want to calculate the total days from start to end date and time.
Also, If start date time column is BLANK, return to count of days including date today.
Thank you

All you need to do is use the following formula: '=(C2-A2)'. This will give you the elapsed time between the two cells and display it as hours. You can take this calculation further by adding dates too. This is useful if you have work shifts that go more than 24 hours or that include two days within a single shift.

Assuming start dates in column A and end dates in column B, you can try
={"Duration in Days"; Arrayformula(if(len(A2:A) * len(B2:B), datedif(A2:A, B2:B, "d"),))}
Change ranges to suit and see if that works?
EXAMPLE
REFERENCES:
DATEDIF

there is a DAYS formula exactly for that purpose:
update:
=INDEX(IFERROR(1/(1/DAYS(
REGEXREPLACE(TO_TEXT(B1:B), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3"),
REGEXREPLACE(TO_TEXT(A1:A), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3")))))
demo sheet

Related

Stop counting after today date passed in Google Sheets

I have a column on Google sheets with different dates, I made a dashboard where you can see the upcoming rows with dates within 5 days away from today. It's a box saying "Starting within 5 days" and shows how many rows starts within 5 days. I made it work, the problem is that once we reached the date and passed it, it keeps counting it.
Let's say a row have a cell with the date 2022-10-20 and today is 2022-10-21, that means it already passed the date, so it should stop counting it. It should only count as "1" if the date set in a cell is within 5 days from todays date.
I hope I was clear enough, I use currently =COUNTIF('Under arbete'!C2:C; "<" & today()+5)
your formula
=COUNTIF('Under arbete'!C2:C; "<" & today()+5)
will work only today. every next day it will be offset by +1 day because TODAY will "recalculate" on a daily basis
you can either feed it today's date like:
=COUNTIF('Under arbete'!C2:C; "<"&"2022-10-20"+5)
or try to freeze today's date like:
=COUNTIF('Under arbete'!C2:C; "<"&LAMBDA(x; x)(TODAY()+5))
update:
=COUNTIFS(Kommande!C2:C; ">="&TODAY();
Kommande!C2:C; "<"&TODAY()+10)
for multiple sheets:
=COUNTIFS({Kommande!C2:C; Sheet2!C2:C}; ">="&TODAY();
{Kommande!C2:C; Sheet2!C2:C}; "<"&TODAY()+10)

Google Sheets. Automatically change given date plus n days

Good afternoon. I have 2 cells for 2 dates with date format on them and formula =DATE(2022; 1; 19). One cell is a first day of a current week period. Another cell is first day of a next week (=B17+7). I want to make both those cells to automatically change +7 days every week after i enter for example the first current date.
You can use for the first day (monday)
=today()-WEEKDAY(today(),2)+1
One way of solving your need while escaping circular dependency error is to do the following:
Keep cell B17 as is (=B13+7), however, instead of putting a date in cell B13, just put the following formula :
=TODAY()-WEEKDAY(TODAY(),2)+1
The result would be that the 2 cells will always update to the correct dates every time you'd open the spreadsheet.

EOMONTH returns the 1st day of the next month for months with 30 days

When I use the formula below the results of the EOMONTH function
returns the start of the next month for any month with 30 days instead of the last day of the specified month. The month and years are correct, so I'm pretty sure it's EOMONTH when used in another function.
For example,the results in B3 should be "11/31/1965" but it returns "12/1/1965".
=DATE(YEAR(B2),MONTH(B2)+6,DAY(TEXT(EOMONTH(MONTH(B2)+6,0))))
I have tried subtracting a day, but it returns the end-of-month -1 for months with 31 days (30). So I have the same problem in the other case.
I have also used IFS() to account for months with 30 days, and it miscalculates the date the same way.
=IFS( MONTH(B2)+6 = 4,DATE(YEAR(B2),MONTH(B2)+6,DAY(EOMONTH(MONTH(B2)+6,0))-2) ,
MONTH(B2)+6 =
6,DATE(YEAR(B2),MONTH(B2)+6,DAY(EOMONTH(MONTH(B2)+6,0))-2) ,
MONTH(B2)+6 =
9,DATE(YEAR(B2),MONTH(B2)+6,DAY(EOMONTH(MONTH(B2)+6,0))-2) ,
MONTH(B2)+6 =
11,DATE(YEAR(B2),MONTH(B2)+6,DAY(EOMONTH(MONTH(B2)+6,0))-2) ,
TRUE ,DATE(YEAR(B2),MONTH(B2)+6,DAY(EOMONTH(MONTH(B2)+6,0)) ) )
The EOMONTH function by itself where I just pass in the date as a string works correctly (column F).
Any Idea on what I'm doing wrong?
Thanks in advance.
Yes, as #player0 has explained, you can't just add something to a month and feed it into eomonth. Try putting
=eomonth(month(B2)+6,0)
into B3 (formatted as a date).
You get
1/31/1900
Why? month(b2)+6 gives 11 (which is just a number). Dates in google sheets are represented as days since 12/31/1899. So 11 formatted as a date gives 1/11/1900. Applying eomonth to that gives the last day of January 1900, which is the 31st. Feeding that into your formula would give 11/31/65, but that date doesn't exist, so you get 12/1/65.
If you want to go forward 6 months and then get the last day of the month, you need
=eomonth(date(year(B2),month(B2)+6,1),0)
You can also use the Edate function, which does not roll over into the first day of the next month:
=eomonth(edate(B2,6),0)
EOMONTH does not understand MONTH. instead, it converts it into date. to use EOMONTH you need to supply it with valid date
=EOMONTH(B2, 0)

How to get the average of the last cells in a column based on the last month?

I have a sheet that contains an amount in column D and the week number(A), month number (B), and year(C). How do I get the average of the last month's amount (D)? So in the example below, I am looking for the average of D251 to D254 based on last month (Column B) 7. Then next month, with it's September, The same cell would average all the "Amounts" in column D for the month of last month, Aug 8th. I hope that all makes sense.
How do I get the average of the last month's amount (D)?
You can use AverageIF, or possibly AverageIFs (plural) to account for prior year. I updated my example. You also might consider a different structure/column for time that combines Year_Month. See example in sheet.
Formula used:
=IFERROR(AVERAGEIFS(D:D,B:B,if(B2=1,12,B2-1),C:C,if(B2=1,C2-1,C2)),"First Period")
See this example.
Please try the following
=AVERAGE(INDEX(FILTER(A2:D,B2:B=MAX(B2:B)),,4))

Automatically find start and end of the work week in a Google Spreadsheet

My work week goes from Monday to Sunday and I need to find a way to have 2 different cells automatically update based on =today() what the actual date of the start and end of the current work week is.
Is there a formula that can find this?
Similarly:
Is there also a similar method to automate the first and last days of the current month in different cells?
Thank you ahead of time for any assistance
Assuming you're referencing a date in A1...
Start of the work week containing that date (assuming work week starts on Monday):
=A1-WEEKDAY(A1;3)
End of the work week:
=A1-WEEKDAY(A1;3)+6
Start of the month:
=EOMONTH(A1;-1)+1
End of the month:
=EOMONTH(A1;0)
I know this is Microsoft Excel documentation, but this describes the EOMONTH function.

Resources