0

Is there any way week can get date range based on week number and year inputs? check this image

enter image description here

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Dev Miro
  • 39
  • 8
  • Possible duplicate of: https://stackoverflow.com/questions/48724512/how-to-get-start-date-and-end-date-of-a-week-from-mysql-when-week-number-is – Tim Biegeleisen Apr 01 '19 at 08:23
  • Possible duplicate of [How to convert number of week into date?](https://stackoverflow.com/questions/7078730/how-to-convert-number-of-week-into-date) – Bernd Buffen Apr 01 '19 at 08:46

1 Answers1

1

The MySQL documentation gives you a hint for a possible solution:

You cannot use format %X%V to convert a year-week string to a date because the combination of a year and week does not uniquely identify a year and month if the week crosses a month boundary. To convert a year-week to a date, you should also specify the weekday:

SELECT STR_TO_DATE('200442 Monday', '%X%V %W');
  -> '2004-10-18'

So you can use the following solution, using STR_TO_DATE and DATE_ADD to get the start and end date value of a specific the week:

SELECT 
    STR_TO_DATE('2019-04 Monday', '%X-%V %W') AS `start`, 
    DATE_ADD(STR_TO_DATE('2019-04 Monday', '%X-%V %W'), INTERVAL 7 DAY) AS `end`

demo on dbfiddle.uk

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87