Reputation: 5
I have uploader.php that will up the thousands of data from .csv going to mysql database.
my scenario are: after i upload all data in .csv i will convert it to mysql readable data types. question is
Any ideas how to convert the datatype from 18-Feb-13 6:19:41 PM data from .csv file to readable data in mysql.
for example: 2013-02-18 18:19:41
Note: I do not wish to edit the timestamp in excel file from readable format in mysql.
many thanks,
Upvotes: 0
Views: 161
Reputation: 3713
you can use DateTime::createFromFormat
:
assuming your date is in a variable called CSV in col 1 :
$date = DateTime::createFromFormat('d-M-y G:i:s A',$csv[1]);
$query = "INSERT INTO yourtable(yourdate) VALUES(".$date->format('Y-m-d h:i:s').")";
Upvotes: 1
Reputation: 3362
Try
$timestamp = strtotime($csv_date);
in PHP and then in mysql query you can do the following:
... FROM_UNIXTIME(' . $timestamp . ') ...
Upvotes: 0
Reputation: 477
Try this
$dat="18-Feb-13 6:19:41 PM";
echo date("Y-m-d H:i:s",strtotime($dat));
Upvotes: 0