title: What is the most straightforward way to pad empty dates in sql results (on either mysql or perl end)?
body: <p>I'm building a quick csv from a mysql table with a query like:</p>
  
  <pre><code>select DATE(date),count(date) from table group by DATE(date) order by date asc;
  </code></pre>
  
  <p>and just dumping them to a file in perl over a:</p>
  
  <pre><code>while(my($date,$sum) = $sth-&gt;fetchrow) {
      print CSV "$date,$sum\n"
  }
  </code></pre>
  
  <p>There are date gaps in the data, though:</p>
  
  <pre><code>| 2008-08-05 |           4 | 
  | 2008-08-07 |          23 | 
  </code></pre>
  
  <p>I would like to pad the data to fill in the missing days with zero-count entries to end up with:</p>
  
  <pre><code>| 2008-08-05 |           4 | 
  | 2008-08-06 |           0 | 
  | 2008-08-07 |          23 | 
  </code></pre>
  
  <p>I slapped together a really awkward (and almost certainly buggy) workaround with an array of days-per-month and some math, but there has to be something more straightforward either on the mysql or perl side. </p>
  
  <p>Any genius ideas/slaps in the face for why me am being so dumb?</p>
  
  <hr>
  
  <p>I ended up going with a stored procedure which generated a temp table for the date range in question for a couple of reasons:</p>
  
  <ul>
  <li>I know the date range I'll be looking for every time</li>
  <li>The server in question unfortunately was not one that I can install perl modules on atm, and the state of it was decrepit enough that it didn't have anything remotely Date::-y installed</li>
  </ul>
  
  <p>The perl Date/DateTime-iterating answers were also very good, I wish I could select multiple answers!</p>