Home > Blockchain >  Query Between Date Range Mysql Php
Query Between Date Range Mysql Php

Time:08-27

I have a query it only show the schedule today my problem is the range of the schedule

datetime_start datetime_end
8/26/22 8/28/22
8/25/22 8/28/22
8/26/22 8/26/22

it will only show this data

datetime_start datetime_end
8/26/22 8/28/22
8/26/22 8/26/22

but i need also to show the 8/25 because it ends on 8/28/22

This is my sample code

SELECT schedule_list.reserved_by, schedule_list.schedule_remarks,
schedule_list.datetime_start, schedule_list.datetime_end, assembly_hall.room_name 
FROM schedule_list  inner join assembly_hall  on assembly_hall.id = schedule_list.assembly_hall_id
                     
WHERE  curdate() between date(datetime_start) AND date(datetime_end) 
and schedule_list.assembly_hall_id=$room_id ORDER BY datetime_start ASC

i dont know what seems to be the problem

CodePudding user response:

curdate() returns date as 'YYYY-MM-DD' (string) or as YYYYMMDD (numeric)

Please use date_format to change the date format in order to use curdate()

curdate() between DATE_FORMAT(datetime_start, "%Y-%m-%d") AND DATE_FORMAT(datetime_end, "%Y-%m-%d") 

CodePudding user response:

First check what date return curdate() what I see is when you post it is 8/26/2022 so 8/25/22 is out of range

  • Related