use Carbon\Carbon; $now = Carbon::now(); $oneHourAgo = Carbon::now()->subHour(); echo $now->diffForHumans($oneHourAgo); // Output: 1 hour ago
use Carbon\Carbon; $date1 = Carbon::create(2022, 12, 31); $date2 = Carbon::create(2023, 1, 1); echo $date1->diffForHumans($date2); // Output: 1 day beforeThis code snippet demonstrates how to calculate the difference between two dates using the diffForHumans method. This example also helps to determine that the package library is Carbon.