DaveC426913
Programmer
I have records with a timestamp field in a format per this sample: 2006-04-18 21:04:30. Ultimately, I want to graph simply the number of records created per hour.
I want it on a timeline that naturally includes all years, months, days and hours from the earliest record to the latest. i.e. my timeline would look like this:
2006-04-18 21:00 : 5
2006-04-18 22:00 : 4
2006-04-18 23:00 : 3
2006-04-19 00:00 : 0
2006-04-18 01:00 : 2
...
2007-01-01 00:00 : 4
etc.
As you can see, it should not skip rows that have zero records.
I started like this:
$sql = "SELECT MIN(StartTime),MAX(StartTime) FROM `AuraUsers` WHERE StartTime IS NOT NULL";
if ($debug==1){ echo $sql."<br>\n"; }
$result = mysql_query($sql);
for ($y=mysql_fetch_array($result,0);$y<=mysql_fetch_array($result,1);$y++){
$sql = "SELECT StartTime FROM `AuraUsers` WHERE StartTime LIKE '".$y."%'";
if ($debug==1){ echo $sql."<br>\n"; }
$result = mysql_query($sql);
}
but I'm thinking this is going to be VERY clunky, since I'll bascially be nesting a loop for each time unit (year, then month, then day, then hour). Also, It'll get real complex trying to loop 28/30/31 days in a month, etc.
Can anyone suggest - or point me at - something more elegant?
I want it on a timeline that naturally includes all years, months, days and hours from the earliest record to the latest. i.e. my timeline would look like this:
2006-04-18 21:00 : 5
2006-04-18 22:00 : 4
2006-04-18 23:00 : 3
2006-04-19 00:00 : 0
2006-04-18 01:00 : 2
...
2007-01-01 00:00 : 4
etc.
As you can see, it should not skip rows that have zero records.
I started like this:
$sql = "SELECT MIN(StartTime),MAX(StartTime) FROM `AuraUsers` WHERE StartTime IS NOT NULL";
if ($debug==1){ echo $sql."<br>\n"; }
$result = mysql_query($sql);
for ($y=mysql_fetch_array($result,0);$y<=mysql_fetch_array($result,1);$y++){
$sql = "SELECT StartTime FROM `AuraUsers` WHERE StartTime LIKE '".$y."%'";
if ($debug==1){ echo $sql."<br>\n"; }
$result = mysql_query($sql);
}
but I'm thinking this is going to be VERY clunky, since I'll bascially be nesting a loop for each time unit (year, then month, then day, then hour). Also, It'll get real complex trying to loop 28/30/31 days in a month, etc.
Can anyone suggest - or point me at - something more elegant?