Getting the number of Saturdays and Sundays in a month I am trying to get the number of Saturdays and Sundays for a given month represented by an end_date and a start date.

I have been trying to understand the algorithm in the SO question here . I have understood the matrix they have created but I don't get the algorithm that is being used, plus the thing is just the opposite of what is needed, and this thing is pretty new to me, mostly I do normal select, insert, update and joins in mysql.

It would be helpful to get some ideas on this issue.
I'll suggest the calendar table also discussed in that thread. It will help for a lot of calculations beside this one. Your query can then be expressed as:

select count( case when DAYOFWEEK(calendar_date) in (1,7) then 1 end)
from Calendar 
where calendar_date between :start_date and :stop_date


or as:

select count(1)
from Calendar 
where calendar_date between :start_date and :stop_date
  and DAYOFWEEK(calendar_date) in (1,7)