Page 1 of 1

Import different type date from csv

Posted: Sun Apr 08, 2012 11:52 am
by krasi_e_d
Hello, guys

I try to import date from csv file like dd.mm.yyyy in my mysql database and the date in csv file is dd/mm/yyyy. How to convert data? This is my code:

Code: Select all

<?php header("Content-Type: text/html; charset=utf8_unicode"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf8_unicode" />
</head>
<body>
<?php

$connec = mysql_connect('localhost','****','***');
mysql_select_db('export_ajur', $connec);

$sql = "LOAD DATA LOCAL INFILE 'purchase_invoice.csv'
                    
                    INTO TABLE invoice
                    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
                    LINES TERMINATED BY '\r\n'
                    IGNORE 1 LINES
                    ";
mysql_query($sql);
if(mysql_error()) {
    echo(mysql_error());
} else {
    echo("Import sucessfull data imported to mysql table.");
}
?> 

Re: Import different type date from csv

Posted: Sun Apr 08, 2012 1:14 pm
by Celauran
DateTime::format()

Also, given the strange formatting, it seems like you must not be using date or datetime column types in your database. You might want to.

Re: Import different type date from csv

Posted: Sun Apr 08, 2012 1:25 pm
by krasi_e_d
Celauran wrote:DateTime::format()

Also, given the strange formatting, it seems like you must not be using date or datetime column types in your database. You might want to.
What you have in mind?