How to get closest date by day of week?

  • A+

I have the weekdays from 1 to 7 (Monday to Sunday).

I want to get the next date, where the day is the specified day (from 1 to 7).

For example, today is 25.09.2018.

When I pass 5 (Friday) I want to get 28.09.2018 which is the next closest Friday.

How can I achieve it? Thanks in advance!


Example for Friday(5)

Carbon::now()     ->next(5)     ->toDateString(); 

More about Carbon library


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: