I am selecting records from my table that have been posted within the past day. This is for an internal site, where there are no posts on Saturdays or Sundays.
SELECT *
FROM table
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
This works fine if today is a weekday or Saturday (where the previous day is Friday). If today is Sunday, I’d like to get records for Friday but currently my code shows records for Saturday (which are obviously blank, given that no one posts on Saturday). How can I fix that?
Thanks!
Have a look at the
WEEKDAYoperator. It returns the index of the day in the week.0 = Monday and 6 = Sunday