MySQL 更新日期时间字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36891872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:45:19  来源:igfitidea点击:

MySQL update datetime field

mysqldatabase

提问by Rocco The Taco

I have the following query that is executing successfully, but it is NOT updating the record. Departure_Date2and Arrival_Date2are datetime fields. I can't for the life of me figure out why? I've tried with a dash and a forwardslash and still nothing.

我有以下查询正在成功执行,但它没有更新记录。Departure_Date2并且Arrival_Date2是日期时间字段。我一辈子都搞不清楚为什么?我试过破折号和正斜杠,但仍然没有。

UPDATE table SET 
Departure_Date2 =  '22/Nov/15 17:37',
Arrival_Date2 =  '22/Nov/15 19:20' 
WHERE PK =131500

回答by Khamar Uz Zama

A datetime data type has the following format: YYYY-MM-DD HH:MM:SS

日期时间数据类型具有以下格式: YYYY-MM-DD HH:MM:SS

For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.

例如,1973 年 12 月 30 日下午 3:30 将存储为 1973-12-30 15:30:00。

回答by Mayank Awasthi

i have tried with timestamp datatype for column :

我已经尝试使用时间戳数据类型为列:

UPDATE wpcads_paypal SET Departure_Date2 =  '22/Nov/15 17:37',
Arrival_Date2 =  '22/Nov/15 19:20'

working well..

运作良好..