Produce data extracts using day field for the Friday before the weekend

Clash Royale CLAN TAG#URR8PPPProduce data extracts using day field for the Friday before the weekend
Using TSQL on SQL Server...
I need to produce extracts that use a pay day column in a database that only holds the day number, for example 26 to produce extracts for the 26th day of the month with a twist if that pay day falls on a weekend then the data for that extract should be extracted the Friday before the weekend.
Has anybody attempted this and able to offer some ways of achieving this through TSQL?
Thanks
1 Answer
1
I'm assuming you have the month and year available too, in which case you can construct a real date, and get the day of week from it as a 1-based number starting at Sunday. So, 6 equals Friday. This will produce 5 for today, as Thursday = 5
SELECT DATEPART(dw, DATEFROMPARTS(2018, 07, 26)) AS [DayOfWeek]
EDIT:
I'll make another assumption, this time that this is somehow possible, like it's always run for the current month. This is a bit dodgy as it all falls apart if it's run too early or too late, but at least it's achievable.
SELECT DATEPART(dw, DATEFROMPARTS(
DATEPART(YEAR, GETDATE()),
DATEPART(MONTH, GETDATE()),
26)) AS [DayOfWeekThisMonth]
No, all I have is the pay day field with a two digit number - no other date fields.
– user3306489
18 hours ago
I'm looking to report on "pay days" that fall on the weekend on the Friday before. Could I create my own table with dates?
– user3306489
18 hours ago
Then I don't see how you can possibly achieve this. The 26th July is Thursday, the 26th August is Sunday. Without the month it's impossible to know which it will be
– Red
18 hours ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you always running this for the current month? Otherwise I cannot see how any logic is expected to guess what month you are running it for.
– MandyShaw
14 hours ago