I am getting a Collection which contains
[80] => Array
(
[date] => Carbon\Carbon Object
(
[date] => 2018-04-04 17:27:24.000000
[timezone_type] => 3
[timezone] => UTC
)
I want to get the date from here, when I do foreach it gives a Carbon\Carbon Object('date' like this, but then can not access date.
Does anyone know any solution?
Carbon - A simple PHP API extension for DateTime. The Carbon class is inherited from the PHP DateTime class. You can see from the code snippet above that the Carbon class is declared in the Carbon namespace. You need to import the namespace to use Carbon without having to provide its fully qualified name each time.
You'll notice the __toString () method is defined which allows a Carbon instance to be printed as a pretty date time string when used in a string context. You can also set the default __toString () format (which defaults to Y-m-d H:i:s) thats used when type juggling occurs. As part of the settings 'toStringFormat' can be used in factories too.
The Carbon class is inherited from the PHP DateTime class. <?php namespace Carbon ; class Carbon extends DateTime { // code here }. You can see from the code snippet above that the Carbon class is declared in the Carbon namespace.
Starting with Carbon 2, timezones are now handled with a dedicated class CarbonTimeZone extending DateTimeZone.
$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(7));
foreach($analyticsData as $data)
{
print_r($data['date']->toDateString());die;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With