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 = $created_at->addMinutes(30); Carbon is installed by default in Laravel and your dates should be automatically mutated by Laravel. Save this answer.
Using the carbon addMinute() or addMinutes() function you can change the minutes in the date in laravel 8. If we need to add minute or more then one minutes in date and time then you can use carbon in laravel. carbon provides addMinute() and addMinutes() method to add minutes on carbon date object.
Save this question. Show activity on this post. $in1 = explode(' ', "clock in time = 20 minutes"); $out1 = explode(' ', "clock out time = 10 minutes"); $start_time1 = $in1[4] .
What is time () in Laravel? The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
You can use core php functions:
//set timezone
date_default_timezone_set('GMT');
$date = new DateTime();
$created_at = $date->format('U = Y-m-d H:i:s');
$unixTimestamp = time() + 1800; // 30 * 60
$date = new DateTime();
$date->setTimestamp($unixTimestamp);
$is_expired = $date->format('U = Y-m-d H:i:s');
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)
Or if you have $dates = []
in your model you should add the created_at
in it like so
protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];
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