Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

feniixx's avatar

Compare dd/mm/aaaa with carbon date?

How could i compare a date with format dd/mm/aaaa with a carbon date to determine if someones birthday is today?

0 likes
5 replies
veve286's avatar

$date=Carbon::parse(your date);
$date->isToday();

mercuryseries's avatar

Add your date field to the $dates attribute of your model like

protected $dates = ['birthday'];

and after that use

$user->birthday->isToday();
veve286's avatar

If it doesn't work . Try this.


echo Carbon::createFromFormat('dd/mm/yyyy', your date)->isToday();

feniixx's avatar

@veve286 , @as-many, the thing is that in a birthday year is not included for the comparison, just day and month... what you've posted compares day/month/year...

mercuryseries's avatar
Level 17

@feniixx After applying the previous steps you can do something like:

$now = \Carbon\Carbon::now();

if($user->birthday->day == $now->day && $user->birthday->month == $now->month){
    ...
}

Please or to participate in this conversation.