Reputation: 10095
I searched a lot on Google to get the start and end date of the current year. Now, After 2 hours of search, posted the query here.
Below is what i have tried so far. but not working.
$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");
can you please guide me in right direction ?
Upvotes: 0
Views: 429
Reputation: 7303
To get the start date: date('Y-01-01')
and end date date('Y-12-31')
.
If you use Carbon, to get the weekdays:
$year = date('Y');
$date = Carbon::create($year, 12, 31, 0, 0, 0);
$date->toDateTimeString($year, 12, 31, 0, 0, 0); // 2016-12-31 00:00:00
$date->format('l'); // Saturday
$date2 = Carbon::create($year, 1, 1, 0, 0, 0);
$date2->toDateTimeString($year, 1, 1, 0, 0, 0); // 2016-01-01 00:00:00
$date2->format('l'); // Firday
Upvotes: 2