pchart - PHP: Split unix timestamp range into 5 chuncks -
i have requirement need extract 5 points unix time stamp or php time stamp range.
for example, 2014-06-26 07:53:26 2014-06-27 07:52:46.
i need 5 points these 2 dates in exact or approximate intervals, chart using pchart.
currently code
$diff = $mintime->diff($maxtime); $range = max($timestamps) - min($timestamps); $cnt = count($timestamps); $temp = ceil($range * (20/100)); for($i=0;$i<$cnt;$i++) { if($i%($cnt/5) == 0) $point[$i] = gmdate("y-m-d h:i:s",min($timestamps) + $temp * ($i+1)); else $point[$i] = null; }
but code returns erratic values. know problem temp variable. me solve this.
thanks
try this:
$from = '2014-06-26 07:53:26'; $to = '2014-06-27 07:52:46'; $diff_stamp = strtotime($to) - strtotime($from); $range = range(strtotime($from), strtotime($to), $diff_stamp/4);
here, $range
array of timestamps. convert each date, use array_map
:
$range = array_map(function($a){return date('y-m-d h:i:s', $a);}, $range);
resources: strtotime(), range(), array_map()
Comments
Post a Comment