I have a table where a date field (datetime type). Stored data like 2015-12-09 11:33:44 .I have datepicker input field to search data which generated date like 2015-12-09.So how can i search data using the given date.Assume that i have many data with same date but different time.Is this possible to get all matched data with a given date?
1 Answer
convert your input date in a date range:
$inpute_date = '2015-12-09';
$start_date = $inpute_date . ' 00:00:00';
$end_date = $inpute_date . ' 23:59:59';
And in your condition:
WHERE your_date_col BETWEEN '$start_date' AND '$end_date'
1 Comment
VolkerK
Just tested my "solution" (using Date()) and yours and ...dang, MyQL really doesn't optimize
WHERE Date(d)='...' to use the index on d exactly like it does for d BETWEEN ... AND .... (It does use the index, but without index push down).