How to get the only hours and minutes in laravel blade?
Asked Answered
D

3

6

I am trying to get hours and minutes and seconds in blade, normally I use like below

{{$calllog['delivery_date']}}

but now my requirement is to get hours and minutes and seconds. here is how I tried to get

$calllog['delivery_date']->todatestring()}}

Yeah, I think I misuse for this function, can someone help me out? I am new in Laravel. Any help would be greatly appreciated.

Debit answered 24/7, 2017 at 16:26 Comment(1)
{{ $calllog['delivery_date']->format('H:i:s') }}?Eshelman
M
12

If your variable is a DateTime, you can use this :

{{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }}

Or simplest way (depends on your version) :

{{ $calllog['delivery_date']->format('H:i:s') }}
Masque answered 24/7, 2017 at 16:31 Comment(1)
{{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }} this one work for me, the below is showing me like "Call to a member function format() on string"Debit
K
5

If you want to get minutes and hours as separate values:

{{ $calllog['delivery_date']->minute }}
{{ $calllog['delivery_date']->hour }}

You you're looking for solution to show hours and minutes as a string, use format().

For example, this will return 02:12:

{{ $calllog['delivery_date']->format('h:i') }}

And this will return 14:12:

{{ $calllog['delivery_date']->format('H:i') }}

http://carbon.nesbot.com/docs/

Karmenkarna answered 24/7, 2017 at 16:32 Comment(2)
i tried above you mentioned its showing like "Call to a member function format() on string" then i tried like this {{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }} ,its worked , anyway sir thank you so much for your answerDebit
@ThanHtutOo since you've shown $calllog['delivery_date']->todatestring()}} I've assumed that it's a Carbon instance.Karmenkarna
N
0

Use this in blade:

date("h:i a")
Niphablepsia answered 25/1, 2022 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.