Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql query by weekday

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading