public function getStartTimeChart($time_frame = 30, $timeSpan = '1 day') { if ($timeSpan == 'MAX') { $oldest_trade = Trade::orderBy('created_at', 'asc')->first(); if (isset($oldest_trade->id)) { $previous_day = strtotime($oldest_trade->created_at); } else { $previous_day = strtotime(date('Y-m-d H:i:s')); } } else { $previous_day = strtotime(date('Y-m-d H:i:s') . " -" . $timeSpan); } // echo "<br>Cur: ".date("Y-m-d H:i:s"); // echo "<br>timeSpan: ".$timeSpan; // echo "<pre>previous_day: "; print_r(date("Y-m-d H:i:s",$previous_day)); echo "</pre>"; // $hour_minute = date('H:i',$previous_day); $hour = date("H", $previous_day); $minute = date("i", $previous_day); if ($minute < $time_frame) { $minute = 0; } else { $minute = $time_frame; } $hour_minute = mktime($hour, $minute, 0); $result['start_time'] = date("H:i", $hour_minute); $date = mktime($hour, $minute, 0, date('m', $previous_day), date('d', $previous_day), date('Y', $previous_day)); $result['start_date'] = date("Y-m-d H:i:s", $date); return $result; }