Query - What is the calc to determine "working days" from a "start date" - weekend

I'm asking this for a fellow team member. They are able to calculate the number of days from when the project started, but we need to exclude the weekends (Saturday & Sunday) from the StartDate. Right now, I am getting 8 days, but I know it should be 6 business days (Monday - Friday).
I hope I am explaining this properly.
Thank you.

Related

SQL Day Count Calculation between two dates using two tables T1 = Days, T2 = Week Ending Date

Picture
I would like to create a query that takes the Week Ending Date (typically a Friday) and calculate the number of Working Days in each Week.
I have a choice of either every day possible (All Days), or just the Working Days. For example, some weeks would be shorter than other due to designated Holidays. I coded each day as either 1 = Working Day, 2 = Sat or Sunday and 3 = Holiday.
Which would be the easier solution? Go exclusively the Working Days off the Working Days Qry against the Week Ending Table? Or use the All Days Qry against the Week Ending Table? Tried looking up as much as possible on this very helpful site, but couldn't quite find a match to this. Thanks
Tried looking up a lot here, but couldn't find an exact match to my problem. Mainly a Design View guy here, with limited SQL experience.
Which would be the easier solution?
I'm not sure, but a simpler method could be to record the holidays separately, and then calculate the difference in workdays between any two dates.
For this, you can use my function DateDiffWorkdays.
For extended date handling and calculation, see my library at GitHub: VBA.Date.

Group data by weeks since the start of event in sql

I’m a data analyst in the insurance industry and we currently have a program in SAS EG that tracks catastrophe development week by week since the start of the event for all of the catastrophic events that are reported.
(I.E week 1 is catastrophe start date + 7 days, week 2 would be end of week 1 + 7 days and so on) then all transaction amounts (dollars) for the specific catastrophes would be grouped into the respective weeks based on the date each transaction was made.
Problem that we’re faced with is we are moving away from SAS EG to GCP big query and the current process of calculating those weeks is a manually read in list which isn’t very efficient and not easily translated to BigQuery.
Curious if anybody has an idea that would allow me to calculate each week number in periods of 7 days since the start of an event in SQL or has an idea specific for BigQuery? There would be different start dates for each event.
It is complex, I know and I’m willing to give more explanation as needed. Open to any ideas for this as I haven’t been able to find anything.

BigQuery UI - How to schedule a query to run on the last day of the month?

I have a query that pulls a summary of metrics for the past month that needs to run on the last day of each month at a set time.
The BigQuery 'Schedule query' UI allows you to choose a date and time to run a query each month but there is no apparent option to choose that last day of the month.
If I simply choose the 31st of the month, what happens if there are only 30-days in that month? Will the query still run?
Or do I have to schedule a query to run on the 27th, 28th, 29th, 30th, 31st of the month to make sure that I don't miss the correct date?
I can't find any mention of this situation in the BigQuery documentation or online so any help/suggestions will be very gratefully received.
I understand that you need to run your query in the last day of each month. However, if you set 31st of the month as the schedule options, it will skip the months which do not have 31 days.
You can check this affirmation, by performing the following test in the BigQuery UI:
In the Schedule query options, under Schedule options, set:
Repeats: Monthly
On the: 31
Start date and run time: set the date to 10th of June (which is a month with 30 days)
Click Schedule
On the left side of the BigQuery UI, click on Scheduled queries
Check the query you saved. Among other details, it should be displayed Next Scheduled.
It will be shown July, 31
As you can see, it skipped the 30th of June. Thus, when you configure your query to run on the 31st of each month, it will ignore the months with less than 31 days. For this reason, I would advise you to select 27th, 28th, 29th, 30th, 31st of each month in order to run it in a manner that suits you.
As a bonus information, you can set up a Custom schedule option, as mentioned here. You can use syntaxes as "1st monday of month 00:00" or "every monday 00:00", here.

Get this week equivalent from last year

Working with SQL 2005 and I am trying to get this current weeks data equivalent from last year.
The week runs from Sunday to Friday. However as today is only Thursday I need the data from Sunday to Thursday from last year on this current date.
When I run the script again tomorrow it would need to be the data from a year ago for Sunday to - Friday.
Not really sure how to do this. Or even where to start, tried lots of things and lots of googling and not got anywhere, any suggestions?

Display the most recent entry in a given week

I have got multiple entries in each week. I would like to see the most recent entry in the current week and the most recent entry the previous week.
Any help is much appreciated.
Your question is very vague.
Query #1:
For the most recent entry this week (including today), try max([DateFieldGoesHere]).
Query #2:
For the most recent entry in the previous week, it depends on how the week is defined.
If your week starts "7 days from now", then you can do a WHERE clause with a datediff of 7 days.
If you week starts on Sunday, then your WHERE will have to take that into consideration.
The datediff functions available to you will depend on the technologies you are using.