Jump to content
Larry Ullman's Book Forums

How Do I Get .csv Date Into Mysql Date


Recommended Posts

Here is .csv file, excel always changes it into type date (not text):

1/1/2014	1	2	3	4	5	6	1/2/2014	7	1	2	3	4	5	1/3/2014	7	1	2	3	4	5	1/4/2014	8	9	1	2	3	4	1/5/2014	8	9	1	2	3	4	

Here is the query ($dd is the date):

$q = "INSERT INTO I_FL_Draws (draw_date, morning_1, morning_2, morning_3, evening_1, evening_2, evening_3) VALUES ($dd, $mb1, $mb2, $mb3, $eb1, $eb2, $eb3)";$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));if ( (!mysqli_error ($dbc)) &&  (1 == mysqli_affected_rows($dbc)) ) {  // If it inserted OK.  $mycount++;} else {  echo "<p class=\"error\">Could not insert one.</p>";  $sqlfailure = 1;} // did not insert ok

And here is how I read $dd from .csv file:

// open uploaded infile for read$fd = fopen ($realfile, "rb") or exit ("Unable to open file!");$mycount = 0;while(!feof($fd) ) {  // Read one line from infile  $oneline = fgetcsv($fd, 1024);  if (isset($oneline[0]))       $dd = $oneline[0];

But here is the oddest thing that I can't figure out. I debugged this. I changed the draw_date column to be not unique and allow null and I used NOW() for the date and it worked. So I then changed that to use $dd and it worked. Then I worked with another similar routine, which didn't work, I came back to this one and now it doesn't work. It inserts NOW() but $dd becomes 0000-00-00.
 

Link to comment
Share on other sites

 Share

×
×
  • Create New...