if(isset($_FILES["name"])){
$up = new Upload($_FILES["name"]);
if($up->uploaded){
$up->Process("./uploads/");
if($up->processed){
/// lee el archivo excel
require_once 'PHPExcel/Classes/PHPExcel.php';
$archivo = "uploads/".$up->file_dst_name;
$inputFileType = PHPExcel_IOFactory::identify($archivo);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($archivo);
//$PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($fecha);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$x_noCliente = $sheet->getCell("A".$row)->getValue();
$x_nombreCliente = $sheet->getCell("B".$row)->getValue();
$x_zv = $sheet->getCell("C".$row)->getValue();
$x_noPedido = $sheet->getCell("D".$row)->getValue();
$x_pedidoCliente = $sheet->getCell("E".$row)->getValue();
$x_FechaPedido = $sheet->getCell("F".$row)->getValue();
$x_importe = $sheet->getCell("G".$row)->getValue();
$x_contrPen = $sheet->getCell("H".$row)->getValue();
$x_pagoCont = $sheet->getCell("I".$row)->getValue();
$x_credEx = $sheet->getCell("J".$row)->getValue();
$x_deudaVen = $sheet->getCell("K".$row)->getValue();
$x_cr = $sheet->getCell("L".$row)->getValue();
$sql = "insert into pedidospendientes (noCliente, nombreCliente, zv, noPedido, pedidoCliente,
FechaPedido, importe, contrPen, pagoCont, credEx, deudaVen, cr, created_at) value ";
$sql .= "
(\"$x_noCliente\",\"$x_nombreCliente\",\"$x_zv\",\"$x_noPedido\",\"$x_pedidoCliente\",\"$x_FechaPedido\",\"$x_importe\",\"$x_contrPen\", \"$x_pagoCont\",\"$x_credEx\", \"$x_deudaVen\",\"$x_cr\",NOW())";
$mysqli->query($sql);
}
unlink($archivo);
}
}
}
echo $sql;
$sql = "insert into pedidospendientes (noCliente, nombreCliente, zv, noPedido, pedidoCliente,
FechaPedido, importe, contrPen, pagoCont, credEx, deudaVen, cr, created_at) value ";
$sql .= "(\"$x_noCliente\",\"$x_nombreCliente\",\"$x_zv\",\"$x_noPedido\",\"$x_pedidoCliente\",CAST(\"$x_FechaPedido\" AS DATE),\"$x_importe\",\"$x_contrPen\", \"$x_pagoCont\",\"$x_credEx\", \"$x_deudaVen\",\"$x_cr\",NOW())";
$sql = "insert into pedidospendientes (
noCliente,
nombreCliente,
zv, noPedido,
pedidoCliente,
FechaPedido,
importe,
contrPen,
pagoCont,
credEx,
deudaVen,
cr, created_at
) value (
'$x_noCliente',
'$x_nombreCliente',
'$x_zv',
'$x_noPedido',
'$x_pedidoCliente',
CAST('$x_FechaPedido' AS DATE),
'$x_importe',
'$x_contrPen',
'$x_pagoCont',
'$x_credEx',
'$x_deudaVen',
'$x_cr',
NOW()
)";
echo "La fecha \"$x_FechaPedido\" <br />";
echo "El query: $sql";
$sql = "insert into pedidospendientes (
noCliente,
nombreCliente,
zv, noPedido,
pedidoCliente,
FechaPedido,
importe,
contrPen,
pagoCont,
credEx,
deudaVen,
cr, created_at
) value (
'$x_noCliente',
'$x_nombreCliente',
'$x_zv',
'$x_noPedido',
'$x_pedidoCliente',
CAST('".date('d/m/Y H:i:s', $x_FechaPedido)."' AS DATE),
'$x_importe',
'$x_contrPen',
'$x_pagoCont',
'$x_credEx',
'$x_deudaVen',
'$x_cr',
NOW()
)";
INSERT INTO ejemplo(campo1,fecha) VALUES('".$_POST['campo1']."',STR_TO_DATE('".$_POST['aquí_va_la_cadena_a_pasar_como_fecha']."','%d/%m/%Y %H:%i:%s'));
INSERT INTO ejemplo(campo1,fecha) VALUES('Ejemplo de fecha en MySQL',STR_TO_DATE('2019/07/15 11:20:00','%d/%m/%Y %H:%i:%s'));
<?php
require 'funcs/conexion.php';
include "class.upload.php";
if(isset($_FILES["name"])){
$up = new Upload($_FILES["name"]);
if($up->uploaded){
$up->Process("./uploads/");
if($up->processed){
/// leer el archivo excel
require_once 'PHPExcel/Classes/PHPExcel.php';
$archivo = "uploads/".$up->file_dst_name;
$inputFileType = PHPExcel_IOFactory::identify($archivo);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($archivo);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$x_noCliente = $sheet->getCell("A".$row)->getValue();
$x_nombreCliente = $sheet->getCell("B".$row)->getValue();
$x_zv = $sheet->getCell("C".$row)->getValue();
$x_noPedido = $sheet->getCell("D".$row)->getValue();
$x_pedidoCliente = $sheet->getCell("E".$row)->getValue();
$x_FechaPedido = $sheet->getCell("F".$row)->getValue();
$x_importe = $sheet->getCell("G".$row)->getValue();
$x_contrPen = $sheet->getCell("H".$row)->getValue();
$x_pagoCont = $sheet->getCell("I".$row)->getValue();
$x_credEx = $sheet->getCell("J".$row)->getValue();
$x_deudaVen = $sheet->getCell("K".$row)->getValue();
$x_cr = $sheet->getCell("L".$row)->getValue();
$sql = "insert into pedidospendientes (
noCliente,
nombreCliente,
zv, noPedido,
pedidoCliente,
FechaPedido,
importe,
contrPen,
pagoCont,
credEx,
deudaVen,
cr, created_at
) value (
'$x_noCliente',
'$x_nombreCliente',
'$x_zv',
'$x_noPedido',
'$x_pedidoCliente',
'$x_FechaPedido',
'$x_importe',
'$x_contrPen',
'$x_pagoCont',
'$x_credEx',
'$x_deudaVen',
'$x_cr',
NOW()
)";
$mysqli->query($sql);
}
unlink($archivo);
}
}
}
//echo "La fecha \"$x_FechaPedido\" <br />";
//echo gettype($x_FechaPedido);
//echo "El query: $sql";
echo "<script>
window.location = 'pedidospendientes.php';
</script>
";
?>
echo gettype($x_FechaPedido);
$x_FechaPedido = $sheet->getCell("F".$row)->getValue();
$x_FechaPedido = date('d/m/Y',PHPExcel_Shared_Date::ExcelToPHP($x_FechaPedido+1));
CAST('".date('d/m/Y', $x_FechaPedido)."' AS DATE)
CAST('".date('Y-m-d', $x_FechaPedido)."' AS DATE)
if(isset($_FILES["name"])){
$up = new Upload($_FILES["name"]);
if($up->uploaded){
$up->Process("./uploads/");
if($up->processed){
/// leer el archivo excel
require_once 'PHPExcel/Classes/PHPExcel.php';
$archivo = "uploads/".$up->file_dst_name;
$inputFileType = PHPExcel_IOFactory::identify($archivo);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($archivo);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$x_noCliente = $sheet->getCell("A".$row)->getValue();
$x_nombreCliente = $sheet->getCell("B".$row)->getValue();
$x_zv = $sheet->getCell("C".$row)->getValue();
$x_noPedido = $sheet->getCell("D".$row)->getValue();
$x_pedidoCliente = $sheet->getCell("E".$row)->getValue();
$x_FechaPedido = $sheet->getCell("F".$row)->getValue();
$x_FechaPedido = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_FechaPedido));
$x_importe = $sheet->getCell("G".$row)->getValue();
$x_contrPen = $sheet->getCell("H".$row)->getValue();
$x_contrPen = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_contrPen));
$x_pagoCont = $sheet->getCell("I".$row)->getValue();
$x_credEx = $sheet->getCell("J".$row)->getValue();
$x_deudaVen = $sheet->getCell("K".$row)->getValue();
$x_cr = $sheet->getCell("L".$row)->getValue();
$sql = "insert into pedidospendientes (
noCliente,
nombreCliente,
zv, noPedido,
pedidoCliente,
FechaPedido,
importe,
contrPen,
pagoCont,
credEx,
deudaVen,
cr, created_at
) value (
'$x_noCliente',
'$x_nombreCliente',
'$x_zv',
'$x_noPedido',
'$x_pedidoCliente',
CAST('".date('Y-m-d', $x_FechaPedido)."' AS DATE),
'$x_importe',
CAST('".date('Y-m-d', $x_contrPen)."' AS DATE),
'$x_pagoCont',
'$x_credEx',
'$x_deudaVen',
'$x_cr',
NOW()
)";
$mysqli->query($sql);
}
unlink($archivo);
}
}
}
echo "<script>
window.location = 'pedidospendientes.php';
</script>
";
?>
<?php
require_once '../../omegaweb/inc/PHPExcel/PHPExcel.php';
$archivo = "pedidospendientes.xlsx";
$inputFileType = PHPExcel_IOFactory::identify($archivo);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($archivo);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$x_noCliente = $sheet->getCell("A".$row)->getValue();
$x_nombreCliente = $sheet->getCell("B".$row)->getValue();
$x_zv = $sheet->getCell("C".$row)->getValue();
$x_noPedido = $sheet->getCell("D".$row)->getValue();
$x_pedidoCliente = $sheet->getCell("E".$row)->getValue();
$x_FechaPedido = $sheet->getCell("F".$row)->getValue();
$x_FechaPedido = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_FechaPedido+1));
$x_importe = $sheet->getCell("G".$row)->getValue();
$x_contrPen = $sheet->getCell("H".$row)->getValue();
$x_contrPen = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_contrPen+1));
$x_pagoCont = $sheet->getCell("I".$row)->getValue();
$x_credEx = $sheet->getCell("J".$row)->getValue();
$x_deudaVen = $sheet->getCell("K".$row)->getValue();
$x_cr = $sheet->getCell("L".$row)->getValue();
$sql = "insert into pedidospendientes (
noCliente,
nombreCliente,
zv, noPedido,
pedidoCliente,
FechaPedido,
importe,
contrPen,
pagoCont,
credEx,
deudaVen,
cr, created_at
) value (
'$x_noCliente',
'$x_nombreCliente',
'$x_zv',
'$x_noPedido',
'$x_pedidoCliente',
CAST('$x_FechaPedido' AS DATE),
'$x_importe',
CAST('$x_contrPen' AS DATE),
'$x_pagoCont',
'$x_credEx',
'$x_deudaVen',
'$x_cr',
NOW()
)<br />";
echo $sql;
}
?>
$x_contrPen = !empty($x_contrPen) ? date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_contrPen)) : null;
$x_fechaEnvio = $sheet->getCell("F".$row)->getValue();
$x_fechaEnvio = !empty($x_fechaEnvio) ? date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_fechaEnvio)) : null;
$x_fechaRecep = $sheet->getCell("G".$row)->getValue();
$x_fechaRecep = !empty($x_fechaRecep) ? date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($x_fechaRecep)) : null;
$x_fechaActual = $sheet->getCell("H".$row)->getValue();
$datetime1 = date_create($x_fechaActual);
$datetime2 = date_create($x_fechaEnvio);
$contador = date_diff($datetime1, $datetime2);
echo $contador->format('%R%a días');
$x_contador = $sheet->getCell("I".$row)->getValue();
$x_contador = $x_fechaActual->diff($x_fechaEnvio);
$sql = "insert into contratospendientes (
fechaEnvio,
fechaActual,
fechaRecep,
contador,
) value (
CAST('$x_fechaEnvio' AS DATE),
NOW(),
CAST('$x_fechaRecep' AS DATE),
'$x_contador',
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
$retorno = Date::excelToDateTimeObject($valor);
echo date_format($retorno, 'd/m/Y H:i:s');