Use Like on Date in sql query

Viewed 43
SELECT survey_id, orchardist_name, village,
panchayat, dev_block, tehsil, district, survey_id AS ACTION
FROM hd_survey_head WHERE created_on BETWEEN '%%' AND '%%' 
AND dev_block='CHAUPAL' AND panchayat LIKE '%%' AND village LIKE '%%'

On my live website, there is a start date and end date option which is mandatory to fill to run a query in the backend to fetch some data with other dropdowns as well. Now the problem is I want to make it optional not mandatory and still run the query is it possible if yes please tell me how to edit this query to work.

1 Answers

You could send dates that are outside the current date range, but you nned to change the app when it comes to year 9999

SELECT survey_id, orchardist_name, village,
panchayat, dev_block, tehsil, district, survey_id AS ACTION
FROM hd_survey_head WHERE created_on BETWEEN '1899-12-31' AND '9999-01-01' 
AND dev_block='CHAUPAL' AND panchayat LIKE '%%' AND village LIKE '%%'
Related