0
How would a function that when called, turns any date (valid) to the contrary?
For example, I typed:
21/04/2017 will return as 2017/04/21;
If I type:
2017/12/31 will transform into 31/12/2017;
0
How would a function that when called, turns any date (valid) to the contrary?
For example, I typed:
21/04/2017 will return as 2017/04/21;
If I type:
2017/12/31 will transform into 31/12/2017;
0
This function does the conversion using strtotime():
<?php
function convData($i){
$i = str_replace('/','-',$i);
return str_replace('-','/',strlen(end(explode('-',$i))) == 4 ?
date("Y-m-d", strtotime($i)) : date("d-m-Y", strtotime($i)));
}
echo convData('21/04/2017');
echo '-----';
echo convData('2017/04/21');
?>
Obs.: strtotime() does not work properly with /, so you need to make a replace of / for - in function.
Browser other questions tagged php date
You are not signed in. Login or sign up in order to post.
I had written wrong :(
– Josué Aleo