Laravel query by date and time

kaks

Query by date and time.

I have table with field and sample data

Schedule
 --date_start     = 2019-05-01  
 --date_end       = 2019-06-30
 --time_start     = 08:00:00
 --time_end       = 10:00:00

My question is can I query it by doing select date by (current_date) if current_date is in range or in between the date_start and date end. the same also in time if time is in range

thanks in advance.

Josh

You can do it with something like this

$current = Schedule::whereDate('start_date', '<=', today())
    ->whereDate('end_date', '>=', today())
    ->whereTime('start_time', '<=', now())
    ->whereTime('end_time', '>=', now())
    ->get();

$current will be the DB records that are for now.

More information at the Docs

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related