Reputation: 43
I have a string 2020-09-18T07:58:03-04:00
which i want to convert into timestamp format before storing to database. anyone can help me with this?
Upvotes: 1
Views: 3939
Reputation: 39
This should do the trick if you want a timestamp:
Carbon::parse('2020-09-18T07:58:03-04:00')->timestamp;
But I don't think that you need a timestamp to store the date. Parsing should be enough.
$model->my_date_field = Carbon::parse('2020-09-18T07:58:03-04:00');
$model->save();
Upvotes: 2
Reputation: 2545
You can do
Carbon::parse('2020-09-18T07:58:03-04:00')->toDateTimeString();
// OR
Carbon::parse('2020-09-18T07:58:03-04:00')->format('Y-m-d H:i:s');
Result: 2020-09-18 07:58:03
Upvotes: 2