我想从MS Access中检索两个不同年份的两个日期之间的数据

时间:2015-01-01 07:39:52

标签: ms-access-2007

select * from rechargetable 
where Format (CurTime, 'Short Date') between  #12/31/2014#  
and  #01/02/2015#  and Channel = 'Channel15' 
order by autono desc

select * from rechargetable 
where Format (CurTime, 'Short Date')>=#12/31/2014#  
and Format (CurTime, 'Short Date')<=#01/02/2015#  and Channel = 'Channel15' 
order by autono desc

它显示了数据库中的所有记录,如果在2014年12月30日到2014年12月31日之间搜索,它可以正常工作

1 个答案:

答案 0 :(得分:0)

格式将任何值更改为字符串,因此您要比较两个字符串。考虑DateValue

SELECT * FROM rechargetable 
WHERE DateValue(CurTime) Between #2014/12/31# And #2015/01/02# 
AND Channel = 'Channel15' 
ORDER BY autono Desc