Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

johndoee's avatar

How can make condition that 10minute > or < than last created_at time from database

i fetch last data created time as

 $lastOHLCtime =  Price::orderBy('id','asc')->get()->last()->created_at;
   
   

i need to do this two conditions

if current time is 10minute >  $lastOHLCtime ,insert new data  //date: 2023-01-12 16:49:00.0 UTC (+00:00)
 if  current time 10 minute  <= $lastOHLCtime ,update data   //date: 2023-01-12 16:49:00.0 UTC (+00:00)

how can do

0 likes
2 replies
vincent15000's avatar

You can define the dates as in your previous post.

$now = Carbon::now();
$creation_date = // creation date of the price
$creation_date_10min = // creation date of the price + 10 min

Then you only need to write a condition.

if ($creation_date_10min > $now) {
	// update
} else {
	// create
}
Rebwar's avatar
Rebwar
Best Answer
Level 32

this is how you can do

if($lastOHLCtime->diffInMinutes(now()) <= 10) {
	// update
} else {
	// create
}
1 like

Please or to participate in this conversation.