简体   繁体   中英

Laravel query by date and time

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM