php mysql date.utc and count the occurance -
need result below have tried lot not successful. count number of date occurrence , display in array. [[date.utc(2011,9,23),1],[date.utc(2011,9,24),2],[date.utc(2011,9,25),5]].
so far able extract date array format, below result. [["03-09-2011"],["06-09-2011"],["06-09-2011"]]. how add row show count of each dates , date date.utc?
please help
my code
$mysql_connect = mysql_connect($db_host, $db_user, $db_pword, $db_name); $query = "select date_format(`timestamp`,'%d-%m-%y') date mytable"; if (!$mysql_connect) die("unable connect database: " . mysql_error()); @mysql_select_db($db_name) or die( "unable select database"); $result = mysql_query($query); $response = array(); $stats = array(); while($row=mysql_fetch_array($result)) { $date = $row ['date']; $stats[] = array ($date); } $response[] = $stats; $fp = fopen('results.json', 'w'); fwrite($fp, json_encode($response)); fclose($fp); //die ("failed execute query: " . mysql_error()); mysql_close($mysql_connect);
you can dates counted out of database group clause:
select date_format(`timestamp`,'%d-%m-%y') date, count(*) frequency mytable group date_format(`timestamp`,'%d-%m-%y') conversion date string timestamp (as javascript's date.utc does) can either done in php or mysql. unix_timestamp(cast(timestamp date)) timestamp date straight out of database.
in php http://php.net/manual/en/function.strtotime.php can used unix timestamp format retrieving: $date_utc = strtotime($row['date']); more control use datetime http://php.net/manual/en/book.datetime.php (strtotime can't configured - uses standard assumptions).
$date_time = datetime::createfromformat('d-m-y', $row['date']); $date_utc = $date_time->gettimestamp();
Comments
Post a Comment