Wednesday, May 23, 2012

MySQL query to display periods between dates

In my table, I have two separate date fields, X and Y. In Field x I have the date of 13/08/2008 and in field Y I have the date of 13/08/2015.



I was wondering if there is a sql way working out what the six monthly date periods are between field X and Y, having the results displayed on separate lines? So, I was hoping to have the following results in two fields:



BEGIN     | END
13-Aug-08 | 13-Feb-09
13-Feb-09 | 13-Aug-09
13-Aug-09 | 15-Feb-10
15-Feb-10 | 13-Aug-10
13-Aug-10 | 14-Feb-11
14-Feb-11 | 15-Aug-11
15-Aug-11 | 13-Feb-12
13-Feb-12 | 13-Aug-12
13-Aug-12 | 13-Feb-13
13-Feb-13 | 13-Aug-13
13-Aug-13 | 13-Feb-14
13-Feb-14 | 13-Aug-14
13-Aug-14 | 13-Feb-15
13-Feb-15 | 13-Aug-15


Is this possible?



Thanks





No comments:

Post a Comment