3

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
2
  • you can do this via date("Y-m-d H:i:s", strtotime($words["return_dt"]." +3 hours")) Commented Nov 25, 2019 at 10:55
  • Is $words an Eloquent model?
    – Rwd
    Commented Nov 25, 2019 at 11:09

5 Answers 5

4

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.

4

For Datetime laravel use Carbon facade. You simply use addHours().

{{ Carbon\Carbon::parse( $words['return_dt'] )->addHours(3) }}
1
  • If you have used laravel then the carbon facade is a good choice. Commented Nov 25, 2019 at 11:13
3

If you use twig you can try this:

{{ $words['return_dt']|date_modify("+3 hours")|date("Y-m-d H:i:s") }}
2

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>
0

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) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.