0

composer install package jenssegers/mongodb

I have a list of documents in which there is a date field as follows

ISODate("2020-05-28T06:34:23.000Z")

how to filter out data with only date and time distinct condition

/** @var $db Jenssegers\Mongodb\Query\Builder */ $db = DB::connection('mgdb')->table('test');

$db
->whereDate('dateShot', '>=', Carbon::parse('2020-05-28'))
->whereDate('dateShot', '<=', Carbon::parse('2020-05-29'))
->whereTime('dateShot', '>=', Carbon::parse('06:00'))
->whereTime('dateShot', '<=', Carbon::parse('08:00'))

or

$db
->whereDate('dateShot', '>=', '2020-05-28')
->whereDate('dateShot', '<=', '2020-05-29')
->whereTime('dateShot', '>=', '06:00')
->whereTime('dateShot', '<=', '08:00')

or

$db
->where('dateShot', '>=', '2020-05-28 00:00:00')
->where('dateShot', '<=', '2020-05-29 23:59:59')
->whereTime('dateShot', '>=', '06:00')
->whereTime('dateShot', '<=', '08:00')

All examples above return null, with the above examples used on mysql is ok.

Thank !

1 Answer 1

0

Please use whereBetween

YourModel::whereBetween('created_at', [new Carbon(2020-05-28 . ' ' . '00:00:00'), new Carbon(2020-05-28 . ' ' . '23:59:59')])
                        ->orderBy("created_at", 'desc');
1
  • How about filtering the time, every day from 6am to 8am? where date 2020-05-01 where date 2020-05-28 where time 06:00 where time 08:00 Jul 1, 2022 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.