Two functions in PHP to convert data from MySQL to the Italian format and vice versa
These two functions written in PHP, are useful when you need to convert dates pulled from a MySQL database in a more readable format, and vice versa when you must convert a date to save in the database MySQL.
<?php
/**
* Converts a MySQL date format (yyyy-mm-dd) in Italian format (dd/mm/yyyy)
* @param type $data
* @return string Returns the converted date
*/
function convertsDataInItalianFormat($data) {
$aaaa = substr ($data, 0, 4 );
$mm = substr ($data, 5, 2 );
$gg = substr ($data, 8, 2 );
$cdata = $gg . "/" . $mm . "/" . $aaaa;
return $cdata;
}
/**
* Converts a Italian date format (dd/mm/yyyy) in MySQL date format (yyyy-mm-dd)
* @param type $data
* @return string Returns the converted date
*/
function convertsDataInMySQLFormat($data) {
$gg = substr ($data, 0, 2 );
$mm = substr ($data, 3, 2 );
$aaaa = substr ($data, 6, 4 );
$cdata = $aaaa . '-' . $mm . '-' . $gg;
return $cdata;
}
?>