从两个日期之间的MS Access表中选择? [英] Select from MS Access Table between two dates?

查看:75
本文介绍了从两个日期之间的MS Access表中选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有字符串字段的MS ACCESS表,我用于存储日期(我有理由不使用Date类型),有没有办法从两个日期之间的表中选择行?因为我尝试过的所有东西似乎都无法正常工作,它使多年,几天甚至几个月都弄糊涂了,这就是我尝试过的东西:

I have an MS ACCESS Table with a string field i use to store dates (I have my reasons to not use a type Date), Is there a way to select rows from the table between two dates ? cuz everything i tried doesnt seem to work, it confuses years, days and months, here is what i tried :

select  *  from audience where Format(auddate, "dd/MM/yyyy") between #01/06/2014# and  #01/08/2014#
select  *  from audience where Format(auddate, "dd/MM/yyyy") > #01/06/2014# and Format(auddate, "dd/MM/yyyy") > #01/08/2014#

除其他外,我得到了一些毫无意义的结果:

among others and i get some meaningless results :

AudDate
2014年6月25日
18/09/2012
12/11/2012
28/01/2013
2011年8月2日
13/10/2011

AudDate
25/06/2014
18/09/2012
12/11/2012
28/01/2013
08/02/2011
13/10/2011

谢谢.

推荐答案

尝试CDate()将您的字符串转换为日期.

Try CDate() to convert your string into a date.

select  *  from audience 
where CDate(audate) between #01/06/2014# and #01/08/2014#;

如果由于CDate无法协调您的格式而导致它不起作用,则可以使用DateSerial(年,月,日)构建日期.您将需要使用mid $和Cint()来构建年,月和日参数.格式为"yyyy-mm-dd"的格式如下:

If it doesn't work because CDate does not reconize your format you can use DateSerial(year, month, day) to build a Date. You will need to use mid$ and Cint() to build the year, month and day arguments. Something like this for a format "yyyy-mm-dd":

DateSerial(CInt(mid(audate, 1, 4)), CInt(mid(audate, 6, 2)), CInt(mid(audate, 9, 2))

希望这会有所帮助.

这篇关于从两个日期之间的MS Access表中选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆