Skip to content

Instantly share code, notes, and snippets.

@hamidhaghdoost
Created December 14, 2016 10:58
Show Gist options
  • Save hamidhaghdoost/7c3bcee06f746d29f42a65a264561ae9 to your computer and use it in GitHub Desktop.
Save hamidhaghdoost/7c3bcee06f746d29f42a65a264561ae9 to your computer and use it in GitHub Desktop.
Get et last n days in Carbon
<?php
public function index()
{
var_dump($this->last_days(5));
}
function last_days($number)
{
$days = [];
$counter = 0;
$step = Carbon::now();
while($counter < $number)
{
$days[$counter][1] = $step->format('Y-m-d 00:00:00');
$days[$counter][0] = $step->subDay()->format('Y-m-d 00:00:00');
//use subWeek,subMonth and others to get last weeks , months and others
$counter++;
}
return $days;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment