1

I'm trying to get the date from a timestamp field in my database, i'm using a timestamp because with date Carbon doesn't add the hours/minutes/seconds in my date, and I need them.

When I try to get the date it works but return a string, and I can't use the Carbon methods with this string, what can I do ? I don't know why it's a string.

Here is what I try to do :

@foreach($disponibilites as $comp)
       <span class="badge badge-pill indigo">{{ $comp->date_debut->diffForHuman() }}</span>
@endforeach
2
  • Are you sure? Carbon::now()->toDateString() produces a full datetime string (2018-06-23 10:30:18), and there are billions of formats to choose from, and Carbon::now()->addHours(2) or whatever will do just what you suggest it doesn't Commented Jun 24, 2018 at 11:50
  • 1
    I found my solution, i do this : {{ \Carbon\Carbon::parse($comp->date_debut)->addHour(2)->diffForHumans() }} Commented Jun 24, 2018 at 12:01

1 Answer 1

1

add the column name in date attribute in model as the following :

 protected $dates = ['date_debut'];
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.