Get More from Dates in Laravel: Extending Date and Time

 How to add months in your Date and DateTime in Laravel using carbon

Add months on your Date and DateTime - Laravel

In this article we will see how to add number of months on a perticular Date or DateTime using carbon . Carbon gives you lots of methods to play with date and time one of them is addMonths() . Let's see how to use it .

UserController.php :

public function addMonths()
    {
        $current_time = Carbon::now();
        $after_month_added = $current_time->addMonths(6);
        //converting the date time to readable form
        $readable_date = $after_month_added->toDateTimeString();
        return $readable_date;
    }

Output :

Add months on your Date and DateTime - Laravel


Previous Post Next Post

Contact Form