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.
You can add hours on current date using carbon in laravel 6, laravel 7, laravel 8 and laravel 9 version. If you need to add hour or more hours in date then you can use carbon in laravel. carbon provide addHour() and addHours() method to add hours on carbon date object.
In addition to template inheritance and displaying data, Blade also provides convenient shortcuts for common PHP control structures, such as conditional statements and loops. These shortcuts provide a very clean, terse way of working with PHP control structures while also remaining familiar to their PHP counterparts.
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') }}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With