Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get time in minutes using carbon class (laravel 5.3)

I am working for notifications and i want to get notification created time in minutes . mean how earlier notification was created. difference of created date time and current date time in minuets this time i am getting just created date in my blade even not in minutes i want to get created at and current date time.

My blade view

<span class="time">{{ Carbon\Carbon::parse($notification->created_at)->format('d-m-Y') }}</span>

However i also have a method in my helper which gives me time in other format like 25 Dec 2017 which is also i am using at different places now i want difference in minutes for above time please help how can i do it

like image 301
Ramzan Mahmood Avatar asked Nov 23 '25 08:11

Ramzan Mahmood


2 Answers

Use diffInMinutes() method:

{{ $notification->created_at->diffInMinutes(Carbon::now()) }}

Note, that you don't need to parse created_at as it's already an instance of Carbon.

like image 89
Alexey Mezenin Avatar answered Nov 24 '25 21:11

Alexey Mezenin


If I understood you correctly:

Time in minutes

Carbon\Carbon::parse($notification->created_at)->diffInMinutes(Carbon\Carbon::now());

Else you should really just read the Carbon docs, they're incredibly extensive and contain an example for pretty much any use case: http://carbon.nesbot.com/docs/#api-difference

like image 41
Loek Avatar answered Nov 24 '25 23:11

Loek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!