Carbon Date startOfDay give me endOfDay date

user3746695 picture user3746695 · May 16, 2017 · Viewed 13.5k times · Source
$dt = Carbon::now();
dd($dt->startOfDay(), $dt->endOfDay());

Carbon {#324 ▼
  +"date": "2017-05-15 23:59:59.000000"
  +"timezone_type": 3
  +"timezone": "Europe/Paris"
}
Carbon {#324 ▼
  +"date": "2017-05-15 23:59:59.000000"
  +"timezone_type": 3
  +"timezone": "Europe/Paris"
}

First variable is the date and hour actually, dd() function is for display content of variables.

startOfDay() method give me the same thing of the endOfDay() method...

Answer

Rashedul Islam Sagor picture Rashedul Islam Sagor · May 16, 2017

Best practices to use copy() method for different date time.

$startDay = Carbon::now()->startOfDay();
$endDay   = $startDay->copy()->endOfDay();

To know more details :

http://carbon.nesbot.com/docs/