MySQL: Find Missing Dates Between a Date Range -


i need mysql query. i've got db table has data jan 1, 2011 thru april 30, 2011. there should record each date. need find out whether date missing table.

so example, let's feb 2, 2011 has no data. how find date?

i've got dates stored in column called reportdatetime. dates stored in format: 2011-05-10 0:00:00, may 5, 2011 12:00:00 am.

any suggestions?

this second answer, i'll post separately.

select date(r1.reportdate) + interval 1 day missing_date reports r1 left outer join reports r2 on date(r1.reportdate) = date(r2.reportdate) - interval 1 day r1.reportdate between '2011-01-01' , '2011-04-30' , r2.reportdate null; 

this self-join reports date such no row exists date following.

this find first day in gap, if there runs of multiple days missing won't report dates in gap.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -