PASSWORD RESET

Your destination for complete Tech news

How to add minutes in a time in Laravel Carbon?

2.34K 0
< 1 min read

In Laravel, Carbon is a popular date/time library that provides an easy way to work with dates and times in PHP. To add minutes to a time using Carbon in Laravel, you can use the addMinutes() method.

Here’s an example code snippet:

use Carbon\Carbon;

$time = Carbon::parse('13:30');

$updatedTime = $time->addMinutes(15);

echo $updatedTime->toTimeString(); // Output: 13:45:00

In this example, we’re starting with a time string of ’13:30′, which is parsed into a Carbon object using the static parse() method. This creates a new Carbon instance representing the given time.

The addMinutes() method is then called on the Carbon object, which adds 15 minutes to the time and returns a new Carbon instance representing the resulting time.

Finally, the toTimeString() method is called on the resulting Carbon instance to output the updated time in the format of “HH:MM:SS”.

The $updatedTime variable is then output using the echo statement, which will output the updated time, in this case “13:45:00”.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.