ms访问日期比较的问题 [英] problem with comparison of dates in ms access
问题描述
你好朋友
在我的Windows窗体应用程序中,我正在使用ms access 2007.我正在使用select query来选择用户输入的两个值之间的数据。
我的查询如下:
Hello friends
In my windows form application i am using ms access 2007. and i am using select query to select data between two values which are entered by user.
my query is as:
"select AMT from SomeTable where DateValue(TestDate) between '" + fromdate + "' and '" + todate + "'"
和我的日期和日期格式为''01 -01-2013''
<当我选择''01 -01-2013''和'10 -05-2013'时,这给了我正确的结果但是当我选择''30 -01-2013'时我没有给出结果'和''10 -05-2013''。这个查询有什么问题plz帮助我
and my from date and to date format is as ''01-01-2013''
this gives me correct result when i select ''01-01-2013'' and ''10-05-2013'' but i not gives result when i select ''30-01-2013'' and ''10-05-2013''. what is the problem with this query plz help me
推荐答案
在Access中,日期用井号#表示。
尝试:
In Access, dates are denoted with a hash #.
Try:
select AMT from SomeTable where DateValue(TestDate) between #"+ format(fromdate, "yyyy/mm/dd") + "# and #"+ format(todate, "yyyy/mm/dd") +"#"
另外,最好格式化你的日期yyyy / mm / dd以避免地区性问题。
Also, it''s a good idea to format your dates yyyy/mm/dd to avoid regional issues.
这篇关于ms访问日期比较的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!