How to exclude weekend and compare current dates in mysql?

Member

by daisha , in category: MySQL , a year ago

How to exclude weekend and compare current dates in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by orpha , 9 months ago

@daisha 

To exclude weekends and compare current dates in MySQL, you can use the WEEKDAY() function along with the CURDATE() function.


Here's an example query that demonstrates how to do this:

1
2
3
SELECT * FROM your_table
WHERE WEEKDAY(your_date_column) NOT IN (5, 6) -- Exclude Saturday (5) and Sunday (6)
AND your_date_column >= CURDATE() -- Compare with current date


Replace your_table with the name of your table and your_date_column with the name of the column that contains the date you want to compare.


This query will select all records where the date is not a weekend day (Saturday or Sunday) and is greater or equal to the current date.