I've a problem in MySql when I try to insert in my database a date.
My table have a datetime column and, when I insert some values with PHP like
INSERT INTO table (column1,column2) VALUES ('1','2010-11-20');
[Column2 is a DATETIME]
My result, in my database is '1' and '0000-00-00 00:00:00' and I don't know why because this worked.... :S.
What can be the problem?
Sorry...I explain more my problem
I read this values from a file with the format '20-11-2010' and I change to the MySql format (it is easy) and write my Insert sentence.
My Insert sentence is good, I put this in other file (like .log) and the result is:
INSERT INTO telephones (telephone,date) VALUES ('123456789','2014-18-11');
But if I look my database, the result is:
'123456789' and '0000-00-00 00:00:00'
Edit:
But in some cases, I've values like '2010-11-20 16:30:20'
. If I change my DATETIME for DATE, I will lose this value.
My data value come from a File and the value is like
'123456789''20-11-2010 16:00:00' [First value is a telephon number and the next is the date]
But in some cases, I recive the date without the time.
When I reed the dates, I changed the value using explode() and I return the value in the next order
$myDate = $date[2]."-".$date[1]."-".$date[0];
When I construct my insert I try the @entiendoNull solution like
date("Y-m-d H:i:s", strtotime($myDate));
but this put in my insert sentence "1970-01-01 XX:xx:xx"