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

johndoee's avatar

how can get data values within current 1 minutes from database by laravel

i can get price data of today by this codes


      $date =Carbon::today()->format('Y-m-d');
     
      $pricelist = Sell::whereDate('created_at', '=', $date)->orderBy('id','asc')->get();
     $priceHL = Sell::whereDate('created_at', '=', $date)->orderBy('price','asc')->get();
 

       $openprice = $pricelist->first()->price;
       $closeprice = $pricelist->last()->price;
       $highprice = $priceHL->last()->price;
       $lowprice = $priceHL->first()->price;

by this way , today open price ,close price ,high price and low price can get , but i want to get by 1 minutes, example price data inserted into database within current 1 minutes , I will fetch them as above OHLC data , How can do that.

0 likes
5 replies
vincent15000's avatar

In which context do you need to retrieve the new prices every minute ?

Do you want for example to dynamically refresh the view with the new prices ?

2 likes
tisuchi's avatar

@zwarkyaw What if you try this?

$now = Carbon::now();
$oneMinuteAgo = $now->subMinutes(1);

$pricelist = Sell::whereBetween('created_at', [$oneMinuteAgo, $now])->get();
3 likes
johndoee's avatar

@tisuchi when i dd( $now, $oneMinuteAgo ); same time get date: 2023-01-12 16:15:36.125262 UTC (+00:00) date: 2023-01-12 16:15:36.125262 UTC (+00:00)

so no between values in them

2 likes
vincent15000's avatar
Level 63

@zwarkyaw

If you want to see the difference, you need to set the $now date as immutable.

$now = CarbonImmutable::now();
$oneMinuteAgo = $now->subMinutes(1);
1 like

Please or to participate in this conversation.