// create a Carbon instance with today's date and time $now = Carbon::now(); // add 5 hours to the current time $future = $now->copy()->addHours(5); echo $future; // output: 2022-01-01 05:00:00
// create a Carbon instance with a specific date $date = Carbon::create(2022, 1, 1); // subtract 7 days from the given date $past = $date->copy()->subDays(7); echo $past; // output: 2021-12-25 00:00:00In both examples, we utilized the Carbon package library to create instances of dates and times, manipulate them by adding or subtracting a specific amount of time, and then display the new date and time.