duansen6750 2015-01-19 14:27
浏览 183

在datetime列中插入日期时SQL中出错

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"

  • 写回答

2条回答 默认 最新

  • duanchi4544 2015-01-19 14:45
    关注

    You try to insert info in a DATE format into a column accepting DATETIME.

    Concluding, you either have to change your column in your table to a "DATE", or (better) just insert 00:00:00 as time:

    INSERT INTO table (column1,column2) VALUES ('1','2010-11-20 00:00:00');
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?