1

I am beginner in Laravel. I use in my project Laravel 5.8. I have this code:

$dataTimeFromDb = '2019-12-28T23:54:04.000000Z';
$userLastActivity = Carbon::parse($dataTimeFromDb)->format('Y-m-d H:m');

In result I have: 2019-12-29 00:12.

I need value from DB in format: Y-m-d H:m. My timezone is Warsaw/Berlin and I save in this format in DB.

How can I repeir it?

6
  • You want to convert this 2019-12-28T23:54:04.000000Z to 2019-12-29 00:12?? Commented Dec 29, 2019 at 9:42
  • In what format you store date in db? Commented Dec 29, 2019 at 9:43
  • In db i have: 2019-12-29 00:54:04 (data format in db: datetime) Commented Dec 29, 2019 at 9:46
  • @traffka something goes wrong when you retrieve it from db Commented Dec 29, 2019 at 9:49
  • @traffka How do you define date column in your model class? Commented Dec 29, 2019 at 9:52

1 Answer 1

1

I think using format only can do the trick. Try it and let me know.

$dataTimeFromDb->format('Y-m-d H:i')
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.