php - Datetime as arrays and convert dateformat and insert into database -


i'm importing data csv file database through html form, having multiple datetime in format 23/06/2015 12:00 convert 2015-23-06 follwing code

$datetime = $emapdata['1']; //format 23/06/2015 12:00 $convertdatetime = datetime::createfromformat('d/m/y', $datetime); $newdatetime = new datetime($convertdatetime); $newdate = $newdatetime->format('y-m-d'); here have date in desire format (2015-06-23) $newtime = $newdatetime->format('h:i'); here have time in format (7:00) 

one solution repeat above code changing variables name convert other datetime in csv did , things working fine i'm thinking use arrays, load datetime arrays , convert datetime , insert converted datetime database.

$datetimearray = array(      '2/17/2015 13:59', '2/20/2015 18:59', '2/05/2015 05:59', '2/15/2015 03:59', '2/19/2015 12:59', '2/10/2015 14:59' ); 

and foreach

foreach ($datetimearray $datetime){      $convertdatetime = datetime::createfromformat('m/d/y', $datetime);     $newdatetime = new datetime($convertdatetime);     $newdate = $newdatetime->format('y-m-d');     $newtime = $newdatetime->format('h:i');     $converteddatetime = $newdate . " " . $newtime;     $finaldatetime[] = $converteddatetime; } print_r($finaldatetime);  

but ouput current datetime

array ( [0] => 2015-07-23 20:44 [1] => 2015-07-23 20:44 [2] => 2015-07-23 20:44 [3] => 2015-07-23 20:44 [4] => 2015-07-23 20:44 [5] => 2015-07-23 20:44 ) 

need sort out.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -