Type in date search field in the format dd / mm / yyyy and search the database in the format YYYY-mm-dd

1

I want to type the date in the form dd / mm / yyyy format but then search the database in the format YYYY-mm-dd, Please have tried everything, from a HELP Ai

    
asked by anonymous 26.07.2018 / 16:19

2 answers

4

In MySQL there is the STR_TO_DATE function, which receives as its parameter string of date and converts to a valid date in the SQL query:

>
SELECT STR_TO_DATE("01/12/2018", '%d/%m/%Y')

Returns: 2018-12-01

    
26.07.2018 / 16:30
2
$data = substr($obj->getData(), 8, 2);
$data .= "/";
$data .= substr($obj->getData(), 5, 2);
$data .= "/";
$data .= substr($obj->getData(), 0, 4);
    
09.08.2018 / 19:36