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 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 ?> 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; ?> 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 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
Archived
This topic is now archived and is closed to further replies.