Reputation: 135
I want to find data between two dates (ex. registration of the users for the month of August) but only the data that was registered during the working days, I want to exclude the data from the weekends.
NOTE: I have found similar question on Stac kOverflow but all of them calculate the number of days between two dates excluding the weekends. I want to search data between two dates but only for the working days. I have a timestamp in my data table, but I don't know how to make an SQL query that will recognize if the timestamp is a working day or weekend.
Upvotes: 2
Views: 1648
Reputation: 311338
You can use the dayofweek
function to exclude weekends:
SELECT *
FROM users
WHERE register_date BETWEEN '2014-08-01' AND '2014-09-01' AND
DAYOFWEEK(registerdate) NOT IN (1, 7)
Note, however, that if you're looking for the users who registered on August, it might be easier to use the month
function instead of the between
operator:
SELECT *
FROM users
WHERE MONTH(register_date) = 8 AND
DAYOFWEEK(registerdate) NOT IN (1, 7)
Upvotes: 4