After I posted this I had an idea which turned into a tutorial, the first question IS POSSIBLE, though there may be a more elegant way to do it.
I'm still wondering if it's possible to create a listing of gaps as a series of rows..
#make a table and insert data
create table diff(ChildID INT(5) unsigned not null default 1, Date1 Date, Date2 Date);
INSERT INTO diff SET ChildID=1, Date1='2007-07-25', Date2='2008-01-13';
INSERT INTO diff SET ChildID=1, Date1='2008-01-14', Date2='2008-01-29';
INSERT INTO diff SET ChildID=1, Date1='2008-01-30', Date2='2009-01-15';
INSERT INTO diff SET ChildID=1, Date1='2009-01-25', Date2='2009-10-01';
INSERT INTO diff SET ChildID=1, Date1='2009-10-02', Date2='9999-99-99';
#first show the dates that fall in a range. my range is 2009-01-01 to 2009-12-31 (the year there was a gap)
SELECT Date1, Date2
FROM diff
WHERE
Date1<='2009-12-31' /* end of period */ AND
Date2>='2009-01-01' /* start of period */ AND ChildID=1
#now add the time difference to demonstrate the math - 4th column is fixed
SELECT
IF(Date1 <'2009-01-01', '2009-01-01', Date1) AS StartInRange,
IF(Date2 >'2009-12-31', '2009-12-31', Date2) AS EndInRange,
DATEDIFF(
IF(Date2 >'2009-12-31', '2009-12-31', Date2),
IF(Date1 <'2009-01-01', '2009-01-01', Date1)
) AS DaysInPeriod,
DATEDIFF('2009-12-31', '2009-01-01') AS OverallDayCount
FROM diff
WHERE
Date1<='2009-12-31' /* end of period */ AND
Date2>='2009-01-01' /* start of period */ AND ChildID=1
#next we group and sum - note the disparity! the difference between 364 and 353 is 11, but the actual days missed between 1/16 and 1/24 inclusive is 9 days..
SELECT
SUM(
DATEDIFF(
IF(Date2 >'2009-12-31', '2009-12-31', Date2),
IF(Date1 <'2009-01-01', '2009-01-01', Date1)
)) AS DaysAssigned,
DATEDIFF('2009-12-31', '2009-01-01') AS OverallDayCount
FROM diff
WHERE
Date1<='2009-12-31' /* end of period */ AND
Date2>='2009-01-01' /* start of period */ AND ChildID=1
GROUP BY ChildID
#the difference is caused by the fact that for n records in a range, we lose n-1 daysin the calculation; i.e. DIFF(1-10) is 9, and DIFF(11-20) is 9, or 18, however DIFF(1-20) is 19
#So, let's do a little more math
SELECT
SUM(
DATEDIFF(
IF(Date2 >'2009-12-31', '2009-12-31', Date2),
IF(Date1 <'2009-01-01', '2009-01-01', Date1)
)) + COUNT(*)-1 AS DaysAssigned,
DATEDIFF('2009-12-31', '2009-01-01') AS OverallDayCount
FROM diff
WHERE
Date1<='2009-12-31' /* end of period */ AND
Date2>='2009-01-01' /* start of period */ AND ChildID=1
GROUP BY ChildID
#there we go! days assigned are 355, plus days NOT assigned (1/16 to 1/24 inclusive = 9) totals 364. Therefore we have a way to check for gaps in assignment by child. We also add in the number of assignments which might be helpful, and the MIN/MAX start and end of the assignments vs. the range being evaluated :
SELECT
ChildID,
DATEDIFF('2009-12-31', '2009-01-01')
- /*minus*/
SUM(
DATEDIFF(
IF(Date2 >'2009-12-31', '2009-12-31', Date2),
IF(Date1 <'2009-01-01', '2009-01-01', Date1)
)) - COUNT(*)+1 AS DaysNotAssigned,
COUNT(*) AS TotalAssignments,
MIN(Date1) AS AssignmentsBegin,
MAX(Date2) AS AssignmentsEnd
FROM diff
WHERE
Date1<='2009-12-31' /* end of period */ AND
Date2>='2009-01-01' /* start of period */
GROUP BY ChildID