-1

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)
Charlieface
  • 52,284
  • 6
  • 19
  • 43
Rivky
  • 1
  • 1
  • 2
    When you read the SQL Server docs for DATETIME functions which ones did you find that might be helpful? Also what datatype is your timestamp column? – Dale K May 08 '22 at 21:00
  • 2
    Take a peek into datename() For Example: Select datename(WEEKDAY,getdate()) – John Cappelletti May 08 '22 at 21:33

1 Answers1

1

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.

Sanjay
  • 46
  • 2