I tried to import an Excel file in the database,but the dates are shown as 5 digit numbers 44605 representing 2/13/2022.What can I use to convert the numbers when trying to import the tables from from the file into the database?The columns for date are data_factura and data_scadenta.
<?php
include("../db/sql/MysqliDb.php");
include('../vendor/autoload.php');
include("../db_conn.php");
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
if(isset($_FILES["filename"]))
{
$file = $_FILES["filename"]["tmp_name"];
$file_open = fopen($file,"r");
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load($file);
$worksheet = $spreadsheet->getActiveSheet();
// Get the highest row and column numbers referenced in the worksheet
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn); // e.g. 5
// for ($row = 1; $row <= $highestRow; ++$row) {
// echo '<tr>' . PHP_EOL;
for ($col = 1; $col <= $highestColumnIndex; ++$col) {
$value = $worksheet->getCellByColumnAndRow($col, 1)->getValue();
if($value == "Cod client")
$column1 = $col;
if($value == "Client")
$column2 = $col;
if($value == "Adresa/sediul social")
$column3 = $col;
if($value == "Data Factura")
$column4 = $col;
if($value == "Scadenta")
$column5 = $col;
if($value == "Total valoare")
$column6 = $col;
if($value == "Total TVA")
$column7 = $col;
if($value == "Total factura curenta cu TVA")
$column8 = $col;
}
// echo $column2;
for ($row = 2; $row <= $highestRow; ++$row) {
$cod_client = $worksheet->getCellByColumnAndRow($column1, $row)->getValue();
$client= $worksheet->getCellByColumnAndRow($column2, $row)->getValue();
$adresa = $worksheet->getCellByColumnAndRow($column3, $row)->getValue();
$data_factura = $worksheet->getCellByColumnAndRow($column4, $row)->getValue();
$data_scadenta = $worksheet->getCellByColumnAndRow($column5, $row)->getValue();
$total_valoare = $worksheet->getCellByColumnAndRow($column6, $row)->getValue();
$total_TVA = $worksheet->getCellByColumnAndRow($column7, $row)->getValue();
$total_factura_curenta = $worksheet->getCellByColumnAndRow($column8, $row)->getValue();
// echo $cod_client.', ';
$adresamodificata= str_replace("'", "",$adresa);
$db->rawQuery("INSERT INTO cod_facturi(cod_client,client,adresa,data_factura,data_scadenta,total_valoare,total_TVA,total_factura_curenta) VALUES ('$cod_client','$client','$adresamodificata','$data_factura','$data_scadenta','$total_valoare','$total_TVA','$total_factura_curenta')");
}