Search code examples
laravellaravel-5php-carbon

How i can get weekend date by giving specific date in laravel?


I am trying to get weekend date of 17-03-2021

Currently in am getting weekend date of current week i want to get by specific date.

Carbon::now()->endOfWeek()->format('d-m-Y')


Solution

  • If Carbon::now()->endOfWeek()->format('d-m-Y') is doing what you want, just not with a specific date, then parse the date you want to base this from:

    Carbon::parse('17-03-2021')->endOfWeek()->format('d-m-Y')

    Also consider ->nextWeekendDay() and ->previousWeekendDay() as ways to access the weekend.