Reputation: 1437
I want to check if there is any data stored in mysql for the upcoming hour. I am using laravel 5.1 and carbon to store and get data.
Here is my code:
* Check if there is any data for the upcoming hour
*
* @return \Illuminate\Http\Response
*/
public function test()
{
$timestamp = Carbon::now('Australia/Brisbane');
// start time with end time check in between
$post = DB::table('posts')
->join('profiles', 'posts.profile_id', '=', 'profiles.id')
->where('posts.scheduled_time', '=', $timestamp->addMinutes(59)->toDateTimeString())
->get();
dd($post);
}
When I run the query I just get an empty array. Im not sure what I've missed.
Upvotes: 1
Views: 71
Reputation: 1561
I hope you are missing here '>=' condition in where clause --
public function test()
{
$timestamp = Carbon::now('Australia/Brisbane');
// start time with end time check in between
$post = DB::table('posts')
->join('profiles', 'posts.profile_id', '=', 'profiles.id')
->where('posts.scheduled_time', '>=', $timestamp->addMinutes(59)->toDateTimeString()),
->where('posts.scheduled_time', '<=', $timestamp->addMinutes(120)->toDateTimeString())
->get();
dd($post);
}
Upvotes: 1