在mysql中的时间的数据类型,MySQL中的日期时间数据类型出错

I have created a table using below mensioned query in MySQL.

CREATE TABLE Pat_Visit (PatientID INT(16), FOREIGN KEY(PatientID) REFERENCES patient_demo(PatientID),Visit_DateTime DATETIME,Visit_Title VARCHAR(6),

DoctorID INT(16),FOREIGN KEY(DoctorID) REFERENCES Doctor(DoctorID));

and i have tried to add some data using query given below.

INSERT INTO Pat_Visit(PatientID,Visit_DateTime,Visit_Title,DoctorID) VALUES (100001,10/24/11 10:00 AM,'PAIN IN JOINTS',920001);

but it ios throwing error. I dont know what is the problem here.can anybody help me please...

解决方案

Try this instruction:

INSERT INTO Pat_Visit(PatientID,Visit_DateTime,Visit_Title,DoctorID)

VALUES (100001,'2011-10-24 10:00:00','PAIN IN JOINTS',920001);

You could convert your date like this:

STR_TO_DATE('10/24/11 10:00 PM','%m/%d/%Y %h:%i %p')

So the instruction is:

INSERT INTO Pat_Visit(PatientID,Visit_DateTime,Visit_Title,DoctorID)

VALUES (100001,STR_TO_DATE('10/24/11 10:00 PM','%m/%d/%Y %h:%i %p'),'PAIN IN JOINTS',920001);

MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS'

format. The supported range is '1000-01-01 00:00:00' to '9999-12-31

23:59:59'.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值