Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

i tried but i seem to fail to implement it can you explain how? the whereBetween expects an array of dates that i already have which in my case is part of the record that i want to retrieve...

kunalthool said:

use whereBetween

http://laravel.com/docs/4.2/queries

0

Are your operators the right way round?

->where('period_starts_at','<=',$dt)
->where('period_ends_at','>=',$dt)
->first();
0

Oh i got the error you cant get the results.

No here is the solution

public function current(){ $from = date('Y-m-d' . '00:00:00', time()); $to = date('Y-m-d' . '24:60:60', time());

    $current = Connection::
        where('user_id',$this->user_id)
        ->where('status','active')
      ->whereBetween('created_at', array($from, $to))->first();
    

return $current; }

Last updated 8 years ago.
0

oops :)

0
public function current(){
 $from = date('Y-m-d' . ' 00:00:00', time()); //need a space after dates.
 $to = date('Y-m-d' . ' 24:60:60', time());

   $current = Connection::
      where('user_id',$this->user_id)
        ->where('status','active')
        ->whereBetween('created_at', array($from, $to))->first();
   
    return $current;
  }
Last updated 7 years ago.
0

Thanks for this - Just to chime in for people using Carbon - make sure you use the toDateTimeString method.

$fromDate = new Carbon('last week'); 
$toDate = new Carbon('now'); 

POST::whereBetween('created_at', array($fromDate->toDateTimeString(), $toDate->toDateTimeString()) )->get();
0

Sign in to participate in this thread!

Eventy

Your banner here too?

threeel threeel Joined 21 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.