英文:
Cannot update the timestamp column in mysql using golang
问题
我在我的应用程序中使用golang。我使用beego框架来创建它。我使用beego ORM来进行数据库操作。我执行以下操作:
num, err := o.Raw("UPDATE apply_leave SET leavestatus=?,resultdate=?
WHERE leaveid=?",leaveResult.LeaveResult, time.Now(),leave_id).Exec()
当我运行这个代码时,我得到以下错误:
"Error 1292: Incorrect datetime value: '15:46:59' for column 'resultdate' at row 1"
请注意,resultdate的类型是timestamp。感谢任何帮助...
英文:
I am using golang in my application.I m using beego framework to create it.I use beego ORM to do the database operations.I do the following
num, err := o.Raw("UPDATE apply_leave SET leavestatus=?,resultdate=?
WHERE leaveid=?",leaveResult.LeaveResult, time.Now(),leave_id).Exec()
When i run this i m getting the following error
"Error 1292: Incorrect datetime value: '15:46:59' for column 'resultdate' at row 1"
Please do note that the resultdate is of type timestamp.Appreciate any help...
答案1
得分: 1
你可以将时间格式化为"2006-01-02 15:04:05"
,并明确指定格式。
将你的代码修改如下可以帮助解决问题:
const MySQLTimeFormat = "2006-01-02 15:04:05"
num, err := o.Raw("UPDATE apply_leave SET leavestatus=?,resultdate=?
WHERE leaveid=?", leaveResult.LeaveResult, time.Now().Format(MySQLTimeFormat), leave_id).Exec()
英文:
You may format it as format time as "2006-01-02 15:04:05"
explicitly
Changing your code as follows will help
const MySQLTimeFormat = "2006-01-02 15:04:05"
num, err := o.Raw("UPDATE apply_leave SET leavestatus=?,resultdate=?
WHERE leaveid=?",leaveResult.LeaveResult, time.Now().Format(MySQLTimeFormat),leave_id).Exec()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论