Weekday Function in T-SQL (1 Viewer)

Kayleigh

Member
Local time
Today, 18:14
Joined
Sep 24, 2020
Messages
706
Hi Would anyone be able to help me convert this Access function to T-SQL:
Weekday(getDate(),2)
 

Kayleigh

Member
Local time
Today, 18:14
Joined
Sep 24, 2020
Messages
706
No I've seen that - it only works in MySQL not SQL Server
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:14
Joined
Oct 29, 2018
Messages
21,474
How about?
Code:
SET DATEFIRST 1
DATEPART(weekday, GETDATE())
 

Kayleigh

Member
Local time
Today, 18:14
Joined
Sep 24, 2020
Messages
706
That sounds like what I am looking for. How would I integrate it into a SELECT query?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:14
Joined
Oct 29, 2018
Messages
21,474
That sounds like what I am looking for. How would I integrate it into a SELECT query?
If you'll always need to have Monday as the first day of the week, you'll have to execute the SET DATEFIRST command first. Otherwise, I would just suggest subtracting a 1 to the result in your query. For example:
Code:
SELECT DATEPART(weekday, GETDATE())-1
 

Users who are viewing this thread

Top Bottom