Possible Duplicate:
How to convert date from one format to another
I am having a spreadsheet with 5 columns. One of that contain date column with format 02-Dec-10.
When I feed that Excel sheet to database it stores as empty date as 0000-00-00 00:00:00.
How can I store it as date?
Edit
This is the code to feed data to database using CSV file
$date = date("d-m-Y");
$databasetable = "sample";
$fieldseparator = ",";
$lineseparator = "
";
$csvfile = "../uploads/" . basename( $_FILES['file']['name']);
$addauto = 0;
$save = 1;
$outputfile = "../temp/output.sql";
if(!file_exists($csvfile)) {
#echo $csvfile;
echo "File not found. Make sure you specified the correct path.
";
return 0;
exit;
}
$file = fopen($csvfile,"r");
if(!$file) {
#echo "Error opening data file.
";
return 0;
exit;
}
$size = filesize($csvfile);
if(!$size) {
echo "File is empty.
";
return 0;
exit;
}
$csvcontent = fread($file,$size);
fclose($file);
$lines = 0;
$queries = "";
$linearray = array();
foreach(split($lineseparator,$csvcontent) as $line) {
$lines++;
$line = trim($line," \t");
$line = str_replace("","",$line);
$line = str_replace("'","\'",$line);
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','",$linearray);
if($addauto)
$query = "insert into $databasetable values('','$linemysql');";
else
$query = "insert into $databasetable values('$linemysql');";
$queries .= $query . "
";
@mysql_query($query);
}
@mysql_close($con);
if($save) {
$file2 = fopen($outputfile,"w");
if(!$file2) {
echo "Error writing to the output file.
";
return 0;
}
else {
fwrite($file2,$queries);
fclose($file2);
return 1;
}
}
//echo "Found a total of $lines records in this csv file.
";