Reputation: 693
How to display diffrence only by days.
Here $price->created_at = 2014-04-28
\Carbon\Carbon::createFromTimeStamp(strtotime($price->created_at))->diffForHumans()
Thanks!
Upvotes: 39
Views: 124354
Reputation: 347
You just need to use startOfDay() function
for example :
$now = Carbon::now();
$now = $now->startOfDay();
that's it!
Upvotes: 0
Reputation: 209
When comparing a value in the past to default now: 1 hour ago, 5 months ago
When comparing a value in the future to default now: 1 hour from now, 5 months from now
When comparing a value in the past to another value: 1 hour before, 5 months before
When comparing a value in the future to another value: 1 hour after, 5 months after
$dt = Carbon::now();
$past = $dt->subMonth();
$future = $dt->addMonth();
echo $dt->subDays(10)->diffForHumans(); // 10 days ago
echo $dt->diffForHumans($past); // 1 month ago
echo $dt->diffForHumans($future); // 1 month before
Upvotes: 1
Reputation: 319
$DeferenceInDays = Carbon::parse(Carbon::now())->diffInDays($dataToCompare);
this is the best one try this
Upvotes: 10
Reputation: 6715
diffInDays function would help.
$cDate = Carbon::parse($date);
return $cDate->diffInDays();
Upvotes: 39
Reputation: 81187
Suppose you want difference to now() and result from diffForHumans suits you except for today:
$created = new Carbon($price->created_at);
$now = Carbon::now();
$difference = ($created->diff($now)->days < 1)
? 'today'
: $created->diffForHumans($now);
edit: no need to call Carbon::now() twice so use $now instead.
Upvotes: 81