How can I put a mask in an HTML form in the date and monetary value fields, then send that data to the database without having to convert the strings to types date
and money
?
I explain:
I have a form with date mask in DD/MM/AAAA
format, however, my SQL Server 2012 database (BD) uses the AAAA-MM-DD
format. When I submit the form for PHP to insert into the DB, the data is sent in the form of string (eg: '31 / 10/2012 '), so I need to do a conversion:
$data = '31/10/2012';
$data_formatada = str_replace('/', '-', $data);
echo date('Y-m-d', strtotime($data_formatada));
The other case is money type data.
The form mask is 9.999.999.999.999,99
and the database has the format 999999999999.99
. When I submit the form for PHP to do the insertion, I have to delete the points and replace the comma by point to only then make insertion of the data in the database.
Question: Is there a more efficient way to insert date and monetary values into the database than the ones I have described?