title: convert the date while import data from excel sheet to the database in php
body: <p>Im having a excel sheet with the format 10/12/2012.then i convert it into csv file i have a date as "41253",When i import that into my database it is storing as 0000-00-00. How to convert the date format while importing. or is there any other way?.</p>
  
  <p>This is the code im using to import to database</p>
  
  <pre><code>if(isset($_POST['Submit']))
  {
  
  GLOBAL $HTTP_POST_FILES;
  
  //$path= $HTTP_POST_FILES['ufile']['name'];
  $path= $_FILES['ufile']['name'];
  //
  if(copy($_FILES['ufile']['tmp_name'], $path))
  {
  
  $host="localhost"; // Host name 
  $username="root"; // Mysql username 
  $password=""; // Mysql password 
  $db_name="xyz"; // Database name 
  $tbl_name="productsegmentmaster"; // Table name 
  require_once '.\phpExcelReader\Excel\reader.php';
  $excel = new Spreadsheet_Excel_Reader();
  $excel-&gt;setOutputEncoding('CP1251');
  $excel-&gt;read($path);
  $x=2;
  $sep = "*";
  ob_start();
  while($x&lt;=$excel-&gt;sheets[0]['numRows']) {
  $y=1;
  $row="";
  while($y&lt;=$excel-&gt;sheets[0]['numCols']) {
  $cell = isset($excel-&gt;sheets[0]['cells'][$x][$y]) ? $excel-&gt;sheets[0]['cells'][$x][$y] : '';
  $row.=($row=="")?"".$cell."":"".$sep."".$cell."";
  $y++;
  } 
  echo $row."\n"; 
  $x++;
  }
      //echo "Sheet count:$x";
  $fp = fopen("data.csv",'w');
  fwrite($fp,ob_get_contents());
  fclose($fp);
  //echo"----";   
  ob_end_clean();
  //connect to the database 
  $connect = mysql_connect("localhost","root",""); 
  mysql_select_db("AmaraRaja",$connect); //select the table 
  //$file = $_FILES['data.csv']['tmp_name']; 
  $handle = fopen('data.csv',"r"); 
  //loop through the csv file and insert into database 
  global $data;
  do { 
  //echo "$data[0]";
  //echo "$data[1]";
  //echo "$data[2]";
          //$post['ProductSegmentCode'] = $data[0];
  //      $post['ProductSegment'] = $data[1];
  //           $post['ProductGroup'] = $data[2];
           $post['ProductCode'] = $data[0];
          $post['WarrantyPeriod'] = $data[1];
          $post['ProRataPeriod'] = $data[2];
          $test = date("Y-m-d",strtotime($data[3]));
          $post['ManufactureDate'] = $test;
         $test1 = date("Y-m-d",strtotime($data[4]));
         echo  $data[4];
          $post['ApplicableFormDate'] = $test1;
           $tname = "productwarranty";
  try
  {
   if($data[0]!="")
   {
       $news-&gt;addNews($post,$tname);
  //mysql_query("INSERT INTO productsegmentmaster VALUES ( '$data[0]', '$data[1]','$data[2]')"); 
  
    }
  }
  catch(Exception $e)
  {
      echo $e.getMessage();
  }
  } while ($data = fgetcsv($handle,1000,"*","'")); 
  echo"&lt;script&gt;alert('File $path Imported Successfully')&lt;/script&gt;";
  }
  fclose($handle);
  
  unlink('data.csv');
  unlink($path);
  }
  
  ?&gt;
  </code></pre>