Welcome Guest, Not a member yet? Register   Sign In
From dd/mm/YYYY
#1

[eluser]Unknown[/eluser]
i have string '25/02/2008'
how to make 2008/02/25
#2

[eluser]xwero[/eluser]
the easiest way is
Code:
list($day,$month,$year) = explode('/','25/02/2008');
echo $year.'/'.$month.'/'.$day;
#3

[eluser]Bruno França[/eluser]
Or...

Code:
function br2mysql($data) {
    return implode("-",array_reverse(explode("/",$data)));
}
function mysql2br($data) {
    return implode("/",array_reverse(explode("-",$data)));
}
#4

[eluser]xwero[/eluser]
Bruno has the easiest way but i suggest you add some form of date validation before you change the format of the string.
#5

[eluser]phpoet[/eluser]
I usually use strtotime() in combination with date() for my date manipulation but this particular starting date format doesn't work with strotime. So this has been a really helpful thread. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB