I have a problem with a rebellious date. It turns out that I have to do a query between two dates, which would be this:
SELECT id FROM `Pedidos` WHERE (`fecha_cobro` BETWEEN '$fechini' AND '$fechafin') AND borrado = 0
I come from a form in which I select the dates that I want to appear in the search. And I convert the date from Spanish to American format so that mysql understands them and I do it like this:
$fechini=date("Y-m-d",strtotime($_POST["Listado_fechaini"]));
$fechafin=date('Y-m-d',strtotime($_POST["Listado_fechafin"]));
But it turns out that $enddate has its own life and only works in certain cases, for example if I put 01/01/2018, but if I put today's date it says that your aunt. I have tried to put single quotes, double quotes, magic quotes, call one of quotes to see if she knows something. But nothing I can not see the error. On the other hand, if I put the date directly in the query, it always works, so I deduce that the error is in the end date.
On the other hand, I have tried to show that it brings that post in case the error was in the form, but no, it brings the correct date (in Spanish format).
Apart from throwing a shoe at Rajoy, what do you think he could do?
Thank you very much for your help.
Hi Killpe,
The problem is that one format uses a separator (
Formato español '/'
) and the other uses a different one (Formato inglés '-'
).You must put a replace for the separators to be able to cast the date correctly, in the following way: