我将其插入到我的列中
PatientID | int(3)
DoctorID | int(3)
DrugID | int(3)
TreatmentResult | varchar(20)
TreatmentDate | date
TreatmentTime | time
INSERT INTO TREATMENT VALUES(1, 23, 1, 'etuigjih', 2015-03-10, '19:25:22');
但随后会导致错误:
Incorrect date value: '2002' for column 'TreatmentDate' at row 1
为什么我的日期是 2015 年,但它发送的是 2002 年?
最佳答案
您需要在日期值两边加上引号,以便将其视为字符串,如下所示:
INSERT INTO TREATMENT VALUES(1, 23, 1, 'etuigjih', '2015-03-10', '19:25:22');
否则 MySQL 会首先将该表达式视为 2015 减 3 减 10,即 2002,然后尝试将其隐式转换为日期,从而给出您看到的错误。
查看“2002”的来源:
mysql> select 2015-03-10;
+------------+
| 2015-03-10 |
+------------+
| 2002 |
+------------+
1 row in set (0.00 sec)
关于MySQL 错误的日期值 : Sending 2015 but instead 2002,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28963079/