-3

How to write the query in mysql where i pass a date variable, it can list down all the date within that week.

etc. if i pass date = 6-12-2016, the query will print:

  date
 4-12-2016
 5-12-2016
 6-12-2016
 7-12-2016
 8-12-2016
 9-12-2016
10-12-2016 
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Ellen Tan
  • 53
  • 1
  • 1
  • 10

1 Answers1

1

You need to generate a Calendar Table like on this SO question:

And then run the following query:

SELECT *
FROM calendar_table
WHERE WEEK(date_column, 0) = WEEK('2016-12-06', 0);

This will produce output you want. 0 number in the argument describe mode in WEEK function. You can change the number to another number according to your needs. See MySQL Documentation about WEEK function.

Community
  • 1
  • 1
Hermanto
  • 552
  • 6
  • 15