Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Carbon get start + end of current week

I am working with Laravel 4 on a tool to publish/schedule restaurant menus on facebook. For this I need a date selector for the current week, starting always on monday and ending always on sunday.

Wireframe for restaurant menu

I'have played around with the examples http://carbon.nesbot.com/docs/#api-getters but without success.

Any idea?

like image 955
Steve Brown Avatar asked Apr 19 '16 13:04

Steve Brown


1 Answers

This is pretty simple with Carbon Library. Here is the code example:

$now = Carbon::now();
$weekStartDate = $now->startOfWeek()->format('Y-m-d H:i');
$weekEndDate = $now->endOfWeek()->format('Y-m-d H:i');

Even you have the option to change start and end day of the week. It is like this,

$start = $now->startOfWeek(Carbon::TUESDAY);
$end = $now->endOfWeek(Carbon::MONDAY);

Source: https://carbon.nesbot.com/docs/#api-getters

like image 193
Its_aggarwal Avatar answered Sep 19 '22 21:09

Its_aggarwal