Get this week equivalent from last year - sql

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?

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.

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

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.

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.

Running APScheduler job the day before the 1st and 3rd Monday each month

I have an APScheduler job that creates a report our client has requested for the first and third Mondays of the month.
To deliver that in time, I want to run the job the day before the first and third Monday, which can't be specified directly in APScheduler.
I noticed another user had this question as well, describing the request as impossible, in the comments of Running APScheduler Job Every nth Day of Month
Here's how I solved it:
scheduler.add_job(func, 'cron', 'day_of_week'='sun', 'day'='last,1-6,14-20')
By specifying the day of the week, and then specifying the days in the month that could apply, it will fire the day before the first and third Mondays. It only fires when all the conditions are met, so the other dates (which won't be Sunday) don't fire.

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.