Skip to content

Instantly share code, notes, and snippets.

@pixel5
Created June 29, 2016 14:53
Show Gist options
  • Save pixel5/5760e31bcd67bba6f885bfc53056701e to your computer and use it in GitHub Desktop.
Save pixel5/5760e31bcd67bba6f885bfc53056701e to your computer and use it in GitHub Desktop.
ridiculous date string comparison
<?php
// Make sales chart data
$i = 1;
foreach ($master['eom'] as $key => $eom) {
$key_compare = intval(substr($key, -2));
$starting_index_month = intval(substr($EOM_STARTING_INDEX + ($i - 1), -2));
$month_compare = $starting_index_month <= 12 ? $starting_index_month : $starting_index_month - 12;
$diff = $key_compare - $month_compare;
$i = $i + $diff;
$m = date('M y', strtotime($eom->datetime));
$labels[$i] = $m;
// Append to data arrays
$data_sold[$i] = intval($eom->sold_units);
$data_returned[$i] = intval(abs($eom->returned_units));
$data_netunits[$i] = $data_sold[$i] - $data_returned[$i];
$i++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment