Laravel Add 30 minutes in field. Example: $is_expired = $created_at + 30minutes;

The name of the picture


Laravel Add 30 minutes in field. Example: $is_expired = $created_at + 30minutes;



I want to add two timestamps, like in this example:


$created_at = "2018-07-23 12:15:43";
$is_expired = $created_at + 30mins;



The content of $is_expired should be 2018-07-23 12:45:43


$is_expired


2018-07-23 12:45:43





Is this in a model?
– apokryfos
10 hours ago





You can use the carbon class in laravel
– Faizan Fayaz
10 hours ago





@apokryfos yes in model.
– Shirjeel Ahmed Khan
10 hours ago




2 Answers
2



Using Carbon you can do


$is_expired = $created_at->addMinutes(30);



Carbon is installed by default in Laravel and your dates should be automatically mutated by Laravel.



If the date is not mutated then you can parse them to Carbon instance using Carbon::Parse($created_at)


Carbon::Parse($created_at)



Or if you have $dates = in your model you should add the created_at in it like so


$dates =


created_at


protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];



You can use core php functions:


//set timezone
date_default_timezone_set('GMT');

$created_at = date('Y-m-d H:m:s');
$is_expired = date('Y-m-d H:m:s', strtotime('+30 minutes', strtotime($created_at));






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP