Jimmery
Jimmery

Reputation: 10119

Problems manipulating a Carbon date object in PHP / Laravel

I am having problems manipulating a Carbon date object ($subscription->updated_at):

$thisDate = $subscription->updated_at->date;
$thisDate = Date($graphDateFormat, $thisDate);

Results in Unknown getter 'date'

$thisDate = $subscription->updated_at;
$thisDate = Date($graphDateFormat, $thisDate);

Results in date() expects parameter 2 to be long, object given

var_dump($subscription->updated_at);

Results in:

object(Carbon\Carbon)[292]
  public 'date' => string '2013-08-21 17:05:19' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)

How can I use a Carbon date inside the Date() function?

Upvotes: 0

Views: 1176

Answers (1)

StuBez
StuBez

Reputation: 1364

You can use the $subscription->updated_at->timestamp to get the UNIX timestamp, which you can pass to date. It might be easier to use the format() method to format the date directly in the Carbon object:

$thisDate = subscription->updated_at->format($graphDateFormat);

Upvotes: 2

Related Questions