numan82 Posted February 24, 2008 Share Posted February 24, 2008 Hi I am having array which stores the Date Format as DD-MM-YYYY now I want to convert this format and store into the DB field but the DB field accept the format YYYY-MM-DD. so what should I do? Thanks! for example 01/03/2008 which need to convert first YYYY-MM-DD Thanks in Advance. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 24, 2008 Share Posted February 24, 2008 Use strtotime() to make it a UNIX timestamp and date() to make it a formatted date again. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted February 24, 2008 Share Posted February 24, 2008 or you could explode and rebuild the date <?php $date = "01-03-2008"; $pieces = explode("-", $date); $newdate = "$pieces[2]-$pieces[1]-$pieces[0]" ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2008 Share Posted February 24, 2008 or use MySQL STR_TO_DATE() function <?php $mydate = '01/03/2008'; $sql = "INSERT INTO tablename (datecol) VALUES (STR_TO_DATE('$mydate', '%d/%m/%Y'))"; Quote Link to comment 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.