Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstnorris's avatar

Blade / helper function, simple date & string conditional formatting question

I have an Event model that has two dates: start and end - they are instances of Carbon. When displaying the dates I would like to do some checking and format a string depending on a few things.

This is what I have so far:

<h6 class="card-subtitle text-muted">
    {{ $event->started_at->format('H:i D d M Y') }} - {{ $event->ended_at->format('H:i D d M Y') }}
</h6>

This prints out "06:30 Sun 20 Mar 2016 - 08:45 Sun 20 Mar 2016 " which is great although it isn't easy/quick/intuitive to tell that the event is only 2hrs 15mins long on the Sunday, I'd rather it say "Sun 20 Mar 2016 06:30 - 08:45". This means that I need to check that the date parts of the timestamps are the same.

Is this a use case for Service Injection or just a helpers.php file?

0 likes
2 replies
jekinney's avatar

If it's common for your project to display that i'ld use a get attribute and do your check if started at < 24 hours for example out put diffForHumans() or your format. Then in your view just use start_at.

mstnorris's avatar

@jekinney I'm not sure if that is what I'm after?

I would like to show if an event is today but that's a separate thing. I just want to change the format from:

**06:30 Sun 20 Mar 2016 - 08:45 Sun 20 Mar 2016** to Sun 20 Mar 2016 06:30 - 08:45.

On a separate note, @JeffreyWay and others, why does the above ** render incorrectly?

Please or to participate in this conversation.