Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carbon get years between specified start year and current year

Is there anyway to get the years between a start year and current year in an array, if possible with Carbon?

So this year the array would be:

[2014,2015,2016]

And next year 2017 will be included:

[2014,2015,2016,2017]

Thanks..

like image 566
MevlütÖzdemir Avatar asked Oct 12 '16 19:10

MevlütÖzdemir


People also ask

How do you set the date on Carbon?

Carbon also allows us to generate dates and times based on a set of parameters. For example, to create a new Carbon instance for a specific date use the Carbon::createFromDate() method, passing in the year, month, day, and timezone, as in the following example.

How do you find the difference between two dates in Laravel Carbon?

You can only use the diffInDays() function on a Carbon instance. You can create a new one by parsing the end date you're receiving. $end = Carbon::parse($request->input('end_date'));

What is Carbon method in Laravel?

Carbon is a package by Brian Nesbit that extends PHP's own DateTime class. It provides some nice functionality to deal with dates in PHP. Specifically things like: Dealing with timezones. Getting current time easily.


1 Answers

Solution:

$years = range(Carbon::now()->year, 2014)
like image 128
MevlütÖzdemir Avatar answered Sep 30 '22 19:09

MevlütÖzdemir