Boa tarde
O código abaixo funciona para importar planilha excel (xls), mas não formata a data corretamente.
Alguém poderia, por gentileza, me ajudar explicando como eu formato o campo do tipo datetime para importar no padrão 2021-06-21 17:00 ?
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
//$objPHPExcel = $objReader->load("…/…/…/tmp/".$this->xls_input_ul_name);
//$worksheetData = $objReader->listWorksheetInfo("…/…/…/tmp/".$this->xls_input_ul_name);
$objPHPExcel = $objReader->load("…/…/…/tmp/".$this->xls_import_ul_name);
$worksheetData = $objReader->listWorksheetInfo("…/…/…/tmp/".$this->xls_import_ul_name);
$totalRows = $worksheetData[0][‘totalRows’];
$totalColumns = $worksheetData[0][‘totalColumns’];
$lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();
$sheet = $objPHPExcel->getSheet(0);
$columnNames = “”;
$rowDate = “”;
for($colum=0;$colum<$totalColumns;$colum++)
{
if($colum==$totalColumns-1)
{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue());
}
else
{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue()).",";
}
}
for($row =2; $row <= $totalRows; $row++)
{
for($colum=0;$colum < $totalColumns;$colum++)
{
if($colum == $totalColumns-1)
{
$rowDate .= “’”.utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."’";
}
else
{
$rowDate .= “’”.utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."’,";
}
}
//echo "INSERT IGNORE INTO indices (".$columnNames.") VALUES (".$rowDate.");";//insere dados
//echo "<br>";
$_insert= "INSERT IGNORE INTO indices(".$columnNames.") VALUES (".$rowDate.");";//insere dados
sc_exec_sql($_insert);
sc_commit_trans();
//print_r($rowDate);
$rowDate = ""; }