Find MAX DATE - 1 DATE in Google Sheets - google-sheets

I have a list of dates in a Google Sheets file that comprises only weekdays. Finding MAX Date from this list is easy, as is finding Max Date - 1 Day.
The issue I need to solve is when Max date is a Monday, which results in no data for Max Date - 1 Day (i.e. a Sunday).
I suspect that if then statements can handle this occurrence, but does a more programatic approach exist using MAX Date? There are solutions for this scenario in Python and SQL, but I found nothing for Google Sheets.

Use WORKDAY and subtract it by 1.
Formula:
=WORKDAY(MAX(A1:A), -1)
Output:

Related

Data Validation + VLOOKUP for Month in Sheets

So I'm currently setting up a sheet that records weekly numbers. I'd love to have something that summarizes the totals (money in, loss, etc) by month. So if the week = 4/4/0 this is April (4) and is calculated just by a drop-down of months. Is such a thing possible in Sheets? I don't need the formula just the clue, really.
Update:
I found something similar:
=SUMIFS($N$7:$N$11,$M$7:$M$11,">="&S8,$M$7:$M$11,"<="&EOMONTH(S8,0))
N7:N11 is amount
M7:M11 is date
S8 is the date I'm querying for
The issue I have with that (^^) formula is that it wants me to present the date as D-MONTH-YYYY
but I'd love the date to just be the MONTH
You can set the column to show just the month by setting its format:
and creating a "Custom date & time"
Alternatively, you can use text to represent the months and convert them to number representation using MONTH(S8&1)
Then, you can do some funky way of converting the "month" to "date" using DATE(YEAR, MONTH(S8&1), 1), where "year" is the year you're querying for.
To sum it up, the formula from your question might look something like this:
=SUMIFS($N$7:$N$11, $M$7:$M$11, ">="&DATE(2022, MONTH(S8&1), 1), $M$7:$M$11, "<="&EOMONTH(2022, MONTH(S8&1), 1),0))

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

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

How to find elapsed time between two datetime values

I working in google sheets. I have already formatted datetime value and separated them in two columns. Now I want to find the time elapsed between these two dates?
date1 : 04/26/21 8:25:00 AM
date2 : 05/01/21 4:46:00 PM
What formula to use in google sheets?
All you need to do is substract the two dates
=H34-G34
Then set the format to Number/Duration of the cell with the formula

Getting data from a google sheet for the previous XX days

I'm logging calls, emails and meetings using Google sheets. I am trying to get a chart of results based on a number of days in the past, 7, 30, last month, current month, etc. I am able to do exactly what I need to do using a fixed date but I can't figure out how to convert that to a date range.
Here is what is working:
={ARRAYFORMULA({UNIQUE(FILTER(CRM!M2:M2510,CRM!N2:N2510>=VALUE("2018-06-01 00:00:00"),CRM!N2:N2510<=VALUE("2018-08-01 23:59:59"),CRM!M2:M2510<>"")),ARRAYFORMULA(COUNTIF(FILTER(CRM!M2:M2510,CRM!N2:N2510>=VALUE("2018-06-01 00:00:00"),CRM!N2:N2510<=VALUE("2018-08-01 23:59:59")),SUBSTITUTE(SUBSTITUTE(UNIQUE(FILTER(CRM!M2:M2510,CRM!N2:N2510>=VALUE("2018-06-01 00:00:00"),CRM!N2:N2510<=VALUE("2018-08-01 23:59:59"),CRM!M2:M2510<>"")),"*","~*"),"?","~?")))})}
I need to change the value from a fixed date to a number of days in the past. What do I need to change in this formula? I tried using TODAY() -7 but I keep getting an error saying that I am missing brackets. When I use (TODAY()-7) I just get an #ERROR.
How can I change the VALUE("fixed date") to VALUE(TODAY -7)?
If your data looks like "2018-06-01 00:00:00".
Then use this conditions for filter to filter the last 7 days:
Arrayformula(datevalue(left(CRM!N2:N2510),10))>=datevalue(today()-7)
,
Arrayformula(datevalue(left(CRM!N2:N2510),10))<=datevalue(today())

How to write a query in Google Spreadsheet that returns date >= today?

I am writing the following =filter formula in Google spreadsheet:
=FILTER('Tab'!6:1963, ‘Tab’!E6:E1963 = "Major", ’Tab’!D6:D1963 > NOW())
Column D are dates and I am interested in including today. For instance today is the 7/19 and I would like to have the data that includes 7/19. My current formula returns values only from tomorrow (7/20). I tried the now()-1 but returned an #VALUE!.
Any help?
NOW() returns a datetime object (which includes the time). If you are comparing with a date, NOW() will (almost :) ) always be greater than the date alone (which would have a time component of 12:00 A.M., which is essentially 0).
Try using TODAY() to get the date only (adding/subtracting 1 will use tomorrow/yesterday, respectively).

Resources