skip to Main Content

I want to query by weekday in a given table on a column storing dates. E.g. select * from MY_TABLE where date_column is 'Monday'

I saw a DAYOFWEEK() function in mysql. But this only seems to manipulate the results of the query.

So is such a query even possible?

2

Answers


  1. The WEEKDAY() function returns the weekday number for a given date.

    Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.

    you need to use weekday instead of dayofweek

    Login or Signup to reply.
  2. Use weekday name:

    SELECT * 
    FROM my_table 
    WHERE DATE_FORMAT(date_column, '%W') = 'Monday';
    

    Use weekday index:

    SELECT * 
    FROM my_table 
    WHERE DAYOFWEEK(date_column) = 2 
    -- WHERE WEEKDAY(date_column) = 0
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search