I have a table which lists every date within the year. Each row also contains a period number from 1 to 13 which loop around each year. It looks something like this:
| Date | Period |
| 2012-12-27 00:00:00 | 12 |
| 2012-12-28 00:00:00 | 12 |
| 2012-12-29 00:00:00 | 13 |
| 2012-12-30 00:00:00 | 13 |
| 2012-12-31 00:00:00 | 13 |
| 2013-01-01 00:00:00 | 13 |
| 2013-01-02 00:00:00 | 13 |
| . . . | 13 |
| 2013-02-10 00:00:00 | 01 |
| . . . | 01 |
| 2013-03-14 00:00:00 | 02 |
| . . . | 02 |
| 2013-05-05 00:00:00 | 03 |
As you can see above, period 13 starts on the 29th of dec 2012 and finishes on the 09th of Febuary 2013. I work this out by getting the first and last dates for period 13.
I need to write a query that will get the period start and end dates for the current period. But I'm having problems because the periods sometimes occur twice a year and sometimes overlap between the years like this example does.
A few more examples:
If getDate() = '2013-02-25 13:45:00' then the period should be 01 and the start and end dates would be '2013-02-10 00:00:00' and '2013-03-14 00:00:00'
If getDate() = '2013-03-15 00:00:00' then the period should be 02 and the start and end dates would be '2013-03-14 00:00:00' and '2013-05-05 00:00:00'
I really hope this makes sense. Let me know if I need to clarify it! Thanks for your help :)