scadran Posted May 13, 2007 Share Posted May 13, 2007 I am getting a date entry through POST by a form byt the format enetered by the user is 'dd/mm/yy' .... how could i use MYSQL PHP syntax to insert the proper format as it is default in the table in my database. which function is it? Rgards Quote Link to comment https://forums.phpfreaks.com/topic/51210-date-format-when-inserting-data/ Share on other sites More sharing options...
paul2463 Posted May 13, 2007 Share Posted May 13, 2007 <?php $date = "14/03/07"; $datearray = explode("/", $date); //explode the date via the "/" $newdate = "$datearray[1]/$datearray[0]/$datearray[2]"; //rearrange the date for the strtotime format to work properly $newerdate = strtotime($newdate); //create the timestamp $insertdate("Y-m-d", $newerdate); //create the date object from the timestamp in mysql format ?> Quote Link to comment https://forums.phpfreaks.com/topic/51210-date-format-when-inserting-data/#findComment-252186 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php $date = "01/01/01"; $newdate = date("Y-m-d",strtotime($date)); echo $newdate; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51210-date-format-when-inserting-data/#findComment-252187 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 ~chigley, Unfortunately, strtotime does not recognise dd/mm/yy format . Try 25/12/07 <?php $date = '25/12/07'; list ($d,$m.$y) = explode ('/', $date); $dbdate = "$y-$m-$d"; // write this to the db if you have DATE or DATETIME field $tstamp = strtotime($dbdate ); // write this to the db if you have timestamp field Quote Link to comment https://forums.phpfreaks.com/topic/51210-date-format-when-inserting-data/#findComment-252305 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.