1

I get the date data as string from Google Analytics like following:

"20190809"

How can I do format with carbon like this:

"2019-08-09"

1 Answer 1

5

You can use Carbon::createFromFormat() to parse a date from an unusual format to a Carbon instance. Then you can format it however you like.

In your case, the following should work:

$date = Carbon::createFromFormat('Ymd','20190809')->format('Y-m-d');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.