jeudi 28 décembre 2017

Check with Carbon if a date is on a different day

I'm trying to determine if 2 dates are on different days using Carbon. To do so, I'm using the method diffInDays(), but it doesn't work as I need.

An example

$dt1 = Carbon::createFromFormat('Y-m-d H:i:s', '2017-12-12 23:00:00');
$dt2 = Carbon::createFromFormat('Y-m-d H:i:s', '2017-12-13 8:00:00');
echo $dt1->diffInDays($dt2);

It says 0 because 24 hours are not past.

I thought to compare $dt1->day and $dt2->day, but if one was 2017-12-13 and the other 2018-1-13 the days would be the same, so I should check the months, the years... and I'm wondering if there is something which already does that out of the box.

Reading the documentation I can't find a method which directly does what I need: it should say "yes, $dt2 is a different day than $dt1". Is that possible with Carbon not writing a custom function?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire