How to convert day/mon/year hour:min:sec to format to be inserted into mysql php -



How to convert day/mon/year hour:min:sec to format to be inserted into mysql php -

i getting 5/10/2014 18:12:22 datetime in $_post['start'] , 19/10/2014 18:12:22 datetime in $_post['end']. on using code

if(isset($_post['start'])) if(!empty($_post['start'])) $start1=mysqli_real_escape_string($con,$_post['start']); if(isset($_post['end'])) if(!empty($_post['end'])) $end1=mysqli_real_escape_string($con,$_post['end']); echo $start = date('y-m-d h:i:s', strtotime($start1)); //returns 2014-05-10 18:12:22 echo '<br>'; echo $end = date('y-m-d h:i:s', strtotime($end1)); //returns 1970-01-01 00:00:00 die();

i don't no i'm doing wrongly please help help appreciated.

if pertinent column datetime/timestamp in table, alternatively utilize datetime class reformat dates before insertion:

simple example:

$start1 = '5/10/2014 18:12:22'; // $_post['start']; $end1 = '19/10/2014 18:12:22'; // $_post['end']; $start_date = datetime::createfromformat($start, 'd/m/y h:i:s'); // feed proper format recognized. $end_date = datetime::createfromformat($end1, 'd/m/y h:i:s'); $start = $start_date->format('y-m-d h:i:s'); $end = $end_date->format('y-m-d h:i:s');

php mysql datetime

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -