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 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 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. 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) Link to comment https://forums.phpfreaks.com/topic/42839-solved-date-format-problem/#findComment-207970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.