The following is the date column and it's vardump :
<td>{{$words['return_dt'] }}</td>
2019-11-25 10:08:55
How can I add three hours to this so that the output would be :
2019-11-25 01:08:55
you can do this via
{{ date("Y-m-d H:i:s", strtotime($words["return_dt"]." +3 hours")) }}
and output will become
2019-11-25 13:08:55
If you need 2019-11-25 01:08:55
then you have to minus 9 Hours.
For Datetime laravel use Carbon facade. You simply use addHours()
.
{{ Carbon\Carbon::parse( $words['return_dt'] )->addHours(3) }}
carbon
facade is a good choice.
Commented
Nov 25, 2019 at 11:13
If you use twig you can try this:
{{ $words['return_dt']|date_modify("+3 hours")|date("Y-m-d H:i:s") }}
Best solution,first convert int timestamp and add 3 hours and convert into your format.
<td>{{ date("Y-m-d H:i:s", strtotime($words["return_dt"]." +3 hours")) }}</td>
By default laravel comes with the Carbon Library
{{ Carbon\Carbon::parse( $words['return_dt'] )->add("3 Hour") }}
And you are not just limited to add only hours
{{ Carbon\Carbon::parse( $words['return_dt'] )->add("5 days 3 Hours 25 Minutes") }}
is Equivalent To
{{ Carbon\Carbon::parse( $words['return_dt'] )->addDays(5)->addHours(3)->addMinutes(25) }}
date("Y-m-d H:i:s", strtotime($words["return_dt"]." +3 hours"))
$words
an Eloquent model?