Search code examples
phplaravellaravel-5php-carbon

Carbon Date startOfDay give me endOfDay date


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


Solution

  • 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/