Reputation:
I want to convert my created_at date into day_of_week format, and I am stuck.
Here is what I did so far :
$max_created_at = DB::table('inventories')->max('created_at');
// 2015-02-17 21:32:30
$day = DateHelper::getDay($max_created_at);
// 17
With the data I have, I want to convert my $day
into day_of_week.
Example, since today is 2/18/2015 Wednesday, it should return 3.
Upvotes: 0
Views: 1297
Reputation: 25384
You don't need the second line to convert to the $day
. Since the created_at
column is an instance of Carbon, you can just do:
$max_created_at->format('N');
Where N
is the "ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)" according to the manual.
Edit: My bad - you probably don't have an instance of Carbon in your case. But you can do date('N', strtotime($max_created_at))
, that'll work equally fine.
Upvotes: 2