How to find the n-th weekday of a month based on @ref_date, @n, and @week_day in MySQL:
SET @ref_date = '2012-09-25';
SET @n = 3; #The third week
SET @week_day = 0; #Monday
The result should be: 2012-09-17.
Any suggestion appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have
@weekdayusing the standard ‘0 == Monday’, but MySql uses a 1-based standard with ‘1 == Sunday’. Assuming we are constrained to say that 0 must equal Monday, you can do this:So as a single query that would be: