How I can get string "today, 12:26"
with Carbon in Laravel?
I have date: "2017-12-17 12:26"
, How can I get these formats?
1) Today, 12:26,
2) 1 hour ago
3) 1 min ago
3) 1 sec ago
4) Yesterday, 12.26
5) 17 december, 12:26
How I can get string "today, 12:26"
with Carbon in Laravel?
I have date: "2017-12-17 12:26"
, How can I get these formats?
1) Today, 12:26,
2) 1 hour ago
3) 1 min ago
3) 1 sec ago
4) Yesterday, 12.26
5) 17 december, 12:26
You should look into diffForHumans method in Carbon. For example:
Carbon::now()->subDays(1)->diffForHumans()
//1 day ago
Carbon::now()->diffForHumans()
//1 second ago
Carbon::now()->subDays(25)->diffForHumans();
// 3 weeks ago
Edit:
The fact that you are using Laravel, note that you can call diffForHumans like this too:
$user->created_at->diffForHumans();
There is a similar thing in Carbon, the ->diffForHumans();
method. Example:
echo Carbon::now()->subDays(1)->diffForHumans();
Produces:
1 day ago
You can always refer to Carbon documentation it is very well-documented. Carbon Documentation.