___ erkimt ___ Insert date into MySQL via PHP ______ qstntxt ___
I want to insert a FORM in HTML that made the field %code% , however it is in the format %code% and mysql only accepts %code% . How do I convert a date to insert correctly in MySQL database using PHP?
I tried to find in many places and nothing to help me, because the data saved in the database is always nothing to do with the typed when I check.
Currently my code has the field %code% in this format:
'$data = $_POST['data'];
echo date('d-m-Y', strtotime($data));
$data = date("Y-m-d",strtotime(str_replace('/','-',$data)));
echo date('Y-m-d', strtotime($data));
$venc_garantia = $_POST['venc_garantia'];
echo date('d-m-Y', strtotime($venc_garantia));
$venc_garantia = date("Y-m-d",strtotime(str_replace('/','-',$venc_garantia)));
echo date('Y-m-d', strtotime($venc_garantia));'
PS: I do not know if interferes with the conversion, but I'm using the form in jQuery one mask for the field %code% , will have problem
?
got thanks to hardware staff link
For those who have had the same doubts that the implementation I used was as follows:
'$data = $_POST['data'];
echo date('d-m-Y', strtotime($data));
$data = date("Y-m-d",strtotime(str_replace('/','-',$data)));
echo date('Y-m-d', strtotime($data));
$venc_garantia = $_POST['venc_garantia'];
echo date('d-m-Y', strtotime($venc_garantia));
$venc_garantia = date("Y-m-d",strtotime(str_replace('/','-',$venc_garantia)));
echo date('Y-m-d', strtotime($venc_garantia));'
The ECHO are just to print the value on the page to see the dates as they are leaving, but it assures me enter successfully in mysql smoothly. However appreciate the help and assistance of all!
@DarkJontex, what I always do and that is very simple, is the following:
%pre%
NOTE: Before one explodes, an echo in the variable that receives the arrival date field:
%pre%
To see if the date is in the format dd / mm / yyyy or yyyy-mm-dd, right?
Always have and always worked.
After receiving the data field of your form, you will have to reverse the date, below a suggestion:
%pre%