Date in Carbon how can i make a query where current month and year onwards for the next 4 years . previous month and year will not display. example given ;
//database
id| month |
1 2019-08-1
//example
September 2019 - onwards
You can do something like this
Model::whereDate('month', '>', Carbon::create(2019, 09, 01))->get();
If you want between now and the next 4 years you can do this
$first = Carbon::create(2019, 09, 01);
$second = $first->copy()->addYears(4);
Model::whereBetween('month', [$first, $second])->get();
Is this what you're looking for?
Something like
$now = Carbow::now();
Model::whereBetween('month', [$now, $now->copy->addYears(4)])->get();
Your question is not clear... but I presume you want something like...
Model::whereMonth('created_at', '>=', now()->format('m'))
->whereYear('created_at', '>=', now()->format('Y'))
->whereDate('created_at', '<=', now()->addYears(4))
->get();
@bobbybouwmann @resin @richard
for more specific on my use case
if in database are empty, the system will display on selection dropdown from January 2019 until December 2023 ( if i want 4 years onwards)
if in database already have August 2019 , in selection dropdown, will not display it.
sorry if my question confusing you guys.
Please sign in or create an account to participate in this conversation.