Reputation: 842
I'm using Carbon
to modify dates in a project. Now I need get the date as today, tomorrow etc. so I tried it with:
\Carbon\Carbon::enableHumanDiffOption(\Illuminate\Support\Carbon::ONE_DAY_WORDS);
$date->diffForHumans();
But for today and tomorrow I receive string like: In 5 hours
and not tomorrow
.
For today i receive: 16 hours ago
and not today
.
The date is from an mysql date
column, eg.: 2018-05-29
.
I read that the needed functionality is currently only available for en
and fr
but also with Carbon::setLocale('en');
i don't receive the needed string.
Using the latest version.
Upvotes: 2
Views: 7265
Reputation: 3935
as far as Carbon
is concerned I haven't seen diffForHumans()
returning as Today or Tomorrow. But there is an hack to fulfil your requirements
$now = Carbon::now();
$future = $now->addDays(30);
echo $now->diffInDays($now->copy()->addDay());
this will return 1 if when dates are of tomorrow, and return 0 when dates are of today so you can now manage it with a simple if statement. For online workaround you can check carbon APIs here
Upvotes: 3