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
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
}
this is how you can do
if($lastOHLCtime->diffInMinutes(now()) <= 10) {
// update
} else {
// create
}
Please sign in or create an account to participate in this conversation.