How to extract day of week from timestamp

2k Views Asked by At

I am trying to extract the day of the week from a timestamp in SQL Server. I am specifically looking for the SQL Server equivalent syntax to EXTRACT. I want to count how many fields are in each day of the week.

This is how I would do it on BigQuery:

SELECT 
    EXTRACT(DAYOFWEEK FROM order_date ) as day,
    count(*) count_trips
FROM `sales.orders` 
group by EXTRACT (DAYOFWEEK FROM order_date)
1

There are 1 best solutions below

0
Sanjay On

Try this:

SELECT DATENAME(WEEKDAY, DATE(timestamp))

example:

SELECT DATENAME(WEEKDAY, '2022/05/08 18:50:30');
Output: Sunday

P.S. I am helping you the day part only considering you know the rest of your code. Feel free to reply this for exact query.