Import csv with wrong format date to MySQL with Symfony-php

I’m trying to upload a csv file to my mysql table with symfony/php.

                                    ...

while (($data = fgetcsv($handle, 0, ";")) !== false) {

                    $count++;
                    if ($count == 1) { continue; }

                    $entity = new Oasice();
 
                    $entity->setCentre($data[0]);
                    $entity->setAffaire($data[1]);
                    $entity->setTypeAffaire($data[2]);
                    $entity->setTypeDossier($data[3]);
                    $entity->setCommune($data[4]);
                    $entity->setCodeInsee($data[5]);
                    $entity->setMoaEr($data[6]);
                    $entity->setDateAmeoAmheo($data[7]); // date
                    $entity->setChargeAffaire($data[8]);
                    // a lot more column...

In this file I have ten columns with dates in the format dd/mm/YYYY which poses a problem for the integration into the database.

I tried the solutions I could find so far (like for example: this) but nothing conclusive.

example

$date = date("Y-m-d", strtotime(str_replace('/', '-', $data[7])));
dump($date)

but my result is often 01-01-1970 or 1970-01-01.

How should I go about it please? what am I doing wrong ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *