Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest finding the date range for each data set then running your query. Hope this helps.</p> <pre><code>&lt;?php /** * Get the average number of rows that were created * during the given date range. * * @param string $range The date range to look for * @return integer The average number of rows created in the given range */ function getAverageRows($range) { $date_begin = null; $date_end = null; switch($range) { case 'year': // Calculate the beginning and end datetime of the past year $date_begin = FIRST_DAY_OF_YEAR . ' 00:00:00'; $date_end = LAST_DAY_OF_YEAR . ' 23:59:59'; break; case 'month': // Calculate the beginning and end datetime of the past month $date_begin = FIRST_DAY_OF_MONTH . ' 00:00:00'; $date_end = LAST_DAY_OF_MONTH . ' 23:59:59'; break; case 'week': // Calculate the beginning and end datetime of the past week $date_begin = FIRST_DAY_OF_WEEK . ' 00:00:00'; $date_end = LAST_DAY_OF_WEEK . ' 23:59:59'; break; default: // Calculate the beginning and end datetime of the past three days $date_begin = SEVENTY_SIX_HOURS_AGO; $date_end = now(); break; } $query = "SELECT COUNT(*) FROM mytable WHERE datetime &gt;= '{$date_begin}' AND datetime &lt;= '{$date_end}'"; // Get and return query results } echo "Average Rows:&lt;br/&gt;"; echo "Past three days: " . getAverageRows() . "&lt;br/&gt;"; echo "Past week: " . getAverageRows('week') . "&lt;br/&gt;"; echo "Past Month: " . getAverageRows('month') . "&lt;br/&gt;"; echo "Past Year: " . getAverageRows('year') . "&lt;br/&gt;"; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload