Sajid Latif
Sajid Latif

Reputation: 119

Datetime format not working. How to use it with Carbon?

Im working in Laravel....

I have made an API integration were I need to handle some input data. One of the date input is a date format. But I just can't figure out how to output the data and save it into my database.

$d = $item->fields['date']->values;
$dt = $d['start'];

When I return a dd($dt) the output is

DateTime @1554076800 {#1106 ▼
  date: 2019-04-01 00:00:00.0 UTC (+00:00)
}

So how can I save the 2019-04-01 into a variable?

I use Laravel and tried with different solutions, but nothing helped.

Upvotes: 1

Views: 226

Answers (1)

George Hanson
George Hanson

Reputation: 3030

Since $dt is a DateTime object, you should just be able to call the format method.

For example:

if ($d = $item->fields['date']) {
    $dt = $d->values['start']->format('Y-m-d');
}

Upvotes: 1

Related Questions