Carbon Date startOfDay give me endOfDay date

Viewed 22264
$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...

3 Answers

Sorry for the late, but someone might see this answer. The thing is when you use

dd($dt->startOfDay(), $dt->endOfDay());

it mutate $dt object that's why it shows both times as one. So make sure to copy it or clone it before use.

$dt->clone()->startOfDay();
$dt->clone()->endOfDay();

Related