首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从PHP中的5位数字日期转换?

问如何从PHP中的5位数字日期转换?
EN

Stack Overflow用户
提问于 2022-04-29 11:33:48
回答 1查看 257关注 0票数 0

我试图在数据库中导入一个Excel文件,但是日期显示为5位数字44605,代表2/13/2022。在尝试将表从文件导入数据库时,我可以使用什么来转换这些数字?日期列是data_factura和data_scadenta。

代码语言:javascript
复制
<?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')");

}
EN

回答 1

Stack Overflow用户

发布于 2022-04-29 11:56:00

在PHP中,我们通过使用date()方法将时间戳转换为日期,该方法接受日期格式和以秒为单位的时间戳。

代码语言:javascript
复制
 date(string dateformat,int timestamp);

 date('m/d/Y H:i:s', time());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72057309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档