Import different type date from csv

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krasi_e_d
Forum Newbie
Posts: 20
Joined: Mon Feb 27, 2012 5:00 am

Import different type date from csv

Post 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.");
}
?> 
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Import different type date from csv

Post 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.
krasi_e_d
Forum Newbie
Posts: 20
Joined: Mon Feb 27, 2012 5:00 am

Re: Import different type date from csv

Post 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?
Post Reply