In my database I am storing week numbers and the relating years. For example something like this:
id | week | year | text
---+------+------+-----------
1 | 23 | 2012 | hello
2 | 27 | 2012 | something
3 | 39 | 2012 | more text
4 | 43 | 2012 | more text
Then on the front end the user can select a week and a year and I then want to be able to return all records between that range. For example selecting between week 25 – 2012 and week 50 – 2012 would return the last 3 records.
I’m not sure whether it will be easier to also hold the first date of the week as well and search on this or if there is a way to search on weeks easily.
Thanks in advance.
Presumably, you want consecutive weeks, even when the year is different. To do this, some arithmetic helps:
This converts, say, week 7 in 2012 to “201207” for comparison purposes.