3
How can I put a mask in an HTML form, in the date and monetary value fields, then send this data to the database without having to convert the strings into types date
and money
?
Explain:
I have a form with date mask in the format DD/MM/AAAA
, however, my database (BD) SQL Server 2012 uses the format AAAA-MM-DD
. When I submit the form for PHP to insert in the BD, the data is sent in the form of string (e.g.: '31/10/2012'), so I need to make 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 PHP pro form to do the insertion, I have to delete the dots and replace the semicolon by dot only to insert the data in the database afterwards.
Question: Is there a more efficient way to enter date and monetary values in the database than the ones I described?
It wouldn’t be more semantic
type='number'
?– Renan Gomes