This question already has an answer here:
i'm writing a search query in a php application where the query its meant to bring up results which matches with the date the user inputs. From the webpage the date sent pattern looks like this "2015/12/17"
and the database also store dates as this "2015-12-17 15:30:12"
.
Now i want to format the query so that it works with the date format the user sends so i can get the results i want.
SELECT *
FROM payments
WHERE pay_date BETWEEN rdate1 AND rdate2
How do i format the rdate1 and rdate2
</div>
Use PHP's built in function str_replace
$var = "2015/12/17";
$var = str_replace($var,'//','-');
use str_to_date
str_to_date(rdate1,'%Y/%m/%d')
try this query :-
SELECT *
FROM payments
WHERE pay_date BETWEEN str_to_date(rdate1,'%Y/%m/%d')
AND str_to_date(rdate2,'%Y/%m/%d')
select date_format(pay_date, '%d/%m/%Y');