Rannie Ollit
Rannie Ollit

Reputation: 160

Return the timestamps only in Laravel Events

When i listen to an event, the returned timestamps of laravel is formatted like this:

created_at: {
  date:"2018-03-04 05:24:25.000000",
  timezone:"UTC"
  timezone_type:3
  }

How can i return the timestamps only in laravel events or like this:

2018-03-04 05:24:25.000000

Upvotes: 4

Views: 103

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163978

Just do this:

$dateTime = $object->created_at->toDateTimeString();

Or create an accessor in the model you use:

public function getCreatedAtStringAttribute($value)
{
    return $value->toDateTimeString();
}

And use it:

$dateTime = $object->created_at_string;

Upvotes: 3

Related Questions