Home > Back-end >  How can I get all start datetime and end datetime of all the months in any year in Laravel
How can I get all start datetime and end datetime of all the months in any year in Laravel

Time:07-16

Please how do I get the start datetime and end datetime of all the months in a given year in Laravel?

CodePudding user response:

You can use this method, If I get your question correctly:

public function getStartAndEndOfMonthForGivenYear(int $year): array
{
    $carbon = Carbon::createFromDate($year);
    $currentYear = $carbon->floorYear();
    $data = array();
    for ($i = 0; $i < 12; $i  ) {
        $data[] = [
            'start' => $currentYear->startOfMonth()->toDateTimeString(),
            'end' => $currentYear->endOfMonth()->toDateTimeString(),
        ];
        $currentYear->startOfMonth()->addMonth();
    }
    return $data;
}

CodePudding user response:

$booking = Booking::min('arrival_date')->first();
 
$reservation = Reservation::max('departure_date')->first();
  • Related