It's exactly the same way in Laravel than in Livewire : in both cases, it's only PHP code.
Trying to calculate age in livewire
There is laravel tutorial on age calculating or a date calculator. I am trying to do the same in livewire.
$newdate = date_create('15-02-2023');
$interval = Carbon::parse($newdate)->age;
Above is what I found. I just wanna make the result with livewire because I am already using livewire in my project. What is the way to do it in livewire?
@webfuelcode this is not a livewire issue, you just need to understand how Carbon and date objects work
for instance, carbon objects are mutable, which means this;
$this->newdate = $this->date-$this->month-$this->year;
gets the date object and tries to subtract whatever is in month and year, and then save to newdate, however, $this->date gets modified in the process so $this->date and $this->newdate end up identical
Your diff attempt, you already have a carbon object so no need to parse it again
$this->interval = $this->newdate->diffInYears($this->to);
Please or to participate in this conversation.