CodeIgniter Forums
From dd/mm/YYYY - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: From dd/mm/YYYY (/thread-11302.html)



From dd/mm/YYYY - El Forum - 09-03-2008

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


From dd/mm/YYYY - El Forum - 09-03-2008

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



From dd/mm/YYYY - El Forum - 09-03-2008

[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)));
}



From dd/mm/YYYY - El Forum - 09-03-2008

[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.


From dd/mm/YYYY - El Forum - 09-03-2008

[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!