[wplug] Convert 6/16/2003 0:00:00 to 2003-06-16?
Chris
vze2f6h6 at verizon.net
Tue Jan 13 13:47:46 EST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> -----Original Message-----
> From: wplug-admin at wplug.org [mailto:wplug-admin at wplug.org] On
> Behalf Of Russ Schneider
> Sent: Tuesday, January 13, 2004 1:29 PM
> To: WPLUG
> Subject: [wplug] Convert 6/16/2003 0:00:00 to 2003-06-16?
>
>
> I have a CSV someone gave me from MS Access.
>
> I need to import this into MySQL.
>
> But the dates read like 6/16/2003 0:00:00 and I need to
> convert them in
> the text file to a what MySQL expects, which is 2003-06-16.
>
> Anyone have any really good ideas?
>
This is just an idea.
Create a copy of the structure of the MySQL database. Change the
timestamp field to a varchar field. Import the file into the new
database. Write a php script that will covert the date to the timestamp
format. Export the data and import into the right database. This should
work.
$sql = "SELECT key, date FROM table";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
list($month, $day, $year) = explode("/", $row[date]);
if (strlen($day) == "1") {
$day = "0".$day;
}
if (strlen($month) == "1") {
$month = "0".$month;
}
$newday = $year.$month.$day;
$sql1 = "UPDATE table SET date='$newday' WHERE key='$row[key]'";
print "Now is $year $month $day<br>$sql1<br><br>";
$result1 = mysql_query($sql1);
}
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
iQA/AwUBQAQ9UgvHK4/UMrUIEQKeMwCg5hq1dASEYrlEN7pTO8qFo0iBxHIAn0jU
FaXcCxH/zUjVbd0P2XRFeYQ1
=0GCG
-----END PGP SIGNATURE-----
More information about the wplug
mailing list