Laravel Carbon Maatwebsite格式日期

时间:2018-12-04 19:08:02

标签: laravel php-carbon maatwebsite-excel

由于以下原因,我试图在导入数据之前用Carbon格式化日期

在导入日期时,即使excel值看起来像101010,它们也会更改为类似于此01/01/1001(示例)的值

上面有一个discussion,但是我对其中的建议并不满意,并且想知道是否还有其他建议或缺少什么?

这是我的导入ClientsImport.php

public function model(array $row)
    {
        return new Client([
            'category' => $row[0],
            'referral_type' => $row[1],
            'first_name' => $row[2],
            'middle_initial' => $row[3],
            'last_name' => $row[4],
            'occupation' => $row[5], 
            'dob' => \Carbon\Carbon::createFromFormat('m/d/Y', $row['6']),
            'email' => $row[7], 
            'cell_phone' => $row[8],
            'work_phone' => $row[9],
            'has_spouse' => $row[10],
            'spouse_first_name' => $row[11], 
            'spouse_middle_initial' => $row[12], 
            'spouse_last_name' => $row[13], 
            'spouse_occupation' => $row[14], 
            'spouse_dob' => \Carbon\Carbon::createFromFormat('m/d/Y', $row['15']), 
            'spouse_email' => $row[16], 
            'spouse_cell_phone' => $row[17], 
            'spouse_work_phone' => $row[18], 
            'street_address' => $row[19],
            'city' => $row[20],
            'state' => $row[21],
            'postal_code' => $row[22], 
        ]);
    }

我尝试了\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['6']) 我得到这个错误A non well formed numeric value encountered

还尝试了\Carbon\Carbon::createFromFormat('m/d/Y', $row['6']) 我得到这个错误The separation symbol could not be found ↵The separation symbol could not be found

0 个答案:

没有答案