use Carbon\Carbon;
$now = Carbon::now();
$daysPassed = $now->day; // Current day of the month
echo $daysPassed;
xxxxxxxxxx
use Carbon\Carbon;
// Date = 7th of July 2021
$year = Carbon::now()->format('Y'); // 2021
$year = Carbon::now()->format('y'); // 21
$year = Carbon::now()->year; // 2021
xxxxxxxxxx
<?php
// Add one month
$currentDateTime = Carbon::now();
$newDateTime = Carbon::now()->addMonth();
// Add more than month
$currentDateTime = Carbon::now();
$newDateTime = Carbon::now()->addMonths(5);
xxxxxxxxxx
use Carbon\Carbon;
// Date = 7th of July 2021
$month = Carbon::now()->format('M'); // July
$month = Carbon::now()->format('m'); // 07
$month = Carbon::now()->month; // 7
xxxxxxxxxx
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class DateController extends Controller
{
public function index()
{
$currentDateTime = Carbon::now();
$newDateTime = Carbon::now()->addMonth();
print_r($currentDateTime);
print_r($newDateTime);
}
}
xxxxxxxxxx
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class DateController extends Controller
{
public function index()
{
$currentDateTime = Carbon::now();
$newDateTime = Carbon::now()->addDay();
print_r($currentDateTime);
print_r($newDateTime);
}
}
xxxxxxxxxx
use Carbon\Carbon;
// if today is January 22, 2021
Carbon::now()->format('M'); // "Jan"
Carbon::now()->format('m'); // "01"
Carbon::now()->month; // 1
use Carbon\Carbon;
// Days passed in a week
$now = Carbon::now();
$daysPassed = $now->dayOfWeek; // 0 (Sunday) to 6 (Saturday)
echo $daysPassed;
// Days passed in a month
$now = Carbon::now();
$daysPassed = $now->day; // Current day of the month
echo $daysPassed;
// Get days passed in a week with Monday as the start
Carbon::setWeekStartsAt(Carbon::MONDAY);
$now = Carbon::now();
$daysPassed = ($now->dayOfWeek + 6) % 7; // 0 (Monday) to 6 (Sunday)
echo $daysPassed;
xxxxxxxxxx
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class DateController extends Controller
{
public function index()
{
$currentDateTime = Carbon::now();
$newDateTime = Carbon::now()->addYear();
print_r($currentDateTime);
print_r($newDateTime);
}
}
xxxxxxxxxx
public function myMonthApts()
{
return $this->appointments()
->whereIn('status_id', [3,4])
->whereYear('created_at', Carbon::now()->year)
->whereMonth('created_at', Carbon::now()->month)
->count();
}