stevesimo Posted March 15, 2007 Share Posted March 15, 2007 Hi, I have a date in dd/mm/yyyy format i.e. 15/03/2007 The problem is that when I am storing this in MySql it uses yyyy/mm/dd format so the value stored in the DB ends up being 2015-03-20 Does anyone know how I can get around this problem? Thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/42839-solved-date-format-problem/ Share on other sites More sharing options...
kenrbnsn Posted March 15, 2007 Share Posted March 15, 2007 Try something like this: <?php function convdate($engdate) { list ($d, $m, $y) = explode('/',$engdate); return ($y . '-' . $m . '-' . $d); } $amerdate = convdate('15/03/2007'); echo $amerdate; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/42839-solved-date-format-problem/#findComment-207954 Share on other sites More sharing options...
Orio Posted March 15, 2007 Share Posted March 15, 2007 Use explode()... <?php $date = "15/03/2007"; list($day, $month, $year) = explode("/", $date); $new_date = $year."/".$month."/".$day; echo $new_date; ?> EDIT - Ken is faster Orio. Quote Link to comment https://forums.phpfreaks.com/topic/42839-solved-date-format-problem/#findComment-207956 Share on other sites More sharing options...
stevesimo Posted March 15, 2007 Author Share Posted March 15, 2007 Thanks guys, the code worked a treat! Steve (Blackpool) Quote Link to comment https://forums.phpfreaks.com/topic/42839-solved-date-format-problem/#findComment-207970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.