用sql语句查询两个时间段的数据

我有一个订单表,要求在两个文本框输入时间,查询出两个时间段的数据,两个文本框的ID分别是datetime1和datetime2,

你订单表里的时间 ,是yyyy/mm/dd格式的date型么?是的话,就需要文本框的时间需要转换格式,语法如下:

select * from 订单表 where time >= to_date(datetime1,'yyyy/mm/dd') and time <= to_date(datetime2,'yyyy/mm/dd')

如果不是,按照需要的格式修改即可。
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2020-12-12
为了避免订单有导入的日期格式冲突,在作时间比较的时候需要将前后两个日期都转换
select * from order a where Convert(date,a.OrderDate)>=Convert(date,【datetime1.value】)
and Convert(date,a.OrderDate)<=Convert(date,【datetime2.value】)本回答被提问者和网友采纳
第2个回答  2013-12-09
select * from  订单表 where time >= datetime1 and time <= datetime2

相似回答