In the database:
Showingpage(inphp):
I would like it to appear as follows: 03-11-2015
You could do as follows using the DateTime class:
<?php
$data = '2015-11-01';
$date = new DateTime($data);
echo $date->format('d-m-Y');//01-11-2015
Or also using regular expression:
$pattern = '/^([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})$/';
$replacement = '$3-$2-$1';
echo preg_replace($pattern, $replacement, $data);//01-11-2015
Or another way could be to use array and string manipulation functions:
$parts = array_reverse(explode('-', $data));
echo implode('-', $parts);//01-11-2015
You can use this function that I made to my site:
<?php
function data($data){
$f = explode("-", $data); //Gera um array com 0 = ano, 1 = mês, 2 = dia
$g = $f[2]."/".$f[1]."/".$f[0]; //Isso é uma string. Formate-a como quiser
return $g;
}
?>
You can use it for time too by changing the explode parameter from "-"
to ":"
.