mysql Date and Time type query

本文介绍了MySQL中关于日期和时间的查询方法及注意事项,包括如何正确使用日期和时间格式进行查询,以及常见的错误示例。

mysql Date Time query

Date query

'2018'
'2018-09'
'2018-09-01'
2018-09
2018-09-01  // sometimes also not works
09
2018
201809
20180901

select * from avaliable_times where course_date = 2018;

mysql> update avaliable_times set still_valid="0" where teacher_id=95 and course_date=2018-07-09 and start_time=080000;
ERROR 1292 (22007): Incorrect date value: '2002' for column 'course_date' at row 1

Time query

'08:00:00'
'08'
08
0800
080000    // strongly recomened

select * from avaliable_times where start_time in ('09:00:00', '08:00:00');

需要注意的是:2018-08-01可以查询,而08:00:00不能查询

mysql> select * from avaliable_times where start_time in (09:00:00, 08:00:00);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':00:00, 08:00:00)' at line 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值