如何根据vb中的访问db之间的2日期获取值 [英] How to get values based on 2 date between in access db in vb

查看:56
本文介绍了如何根据vb中的访问db之间的2日期获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有访问数据库,其中包含日期作为一列,基于需要获取值的日期值。

在我的访问数据库中

列名PDate及其数据类型是日期/时间和一般日期格式5/8/2015 3:58:39 PM



以下是我在Access db中的数据



Hi I have access database ,which contains date as one column,based on that date value need to get values.
In my access db
Column name PDate and its datatype is Date/Time and General Date format "5/8/2015 3:58:39 PM"

below is my data in Access db

BMID    UserId    PDate                    PName
50      1        5/8/2015 3:58:39 PM     Aravind
51      1        6/8/2015 3:59:47 PM     Aravind
52      1        8/8/2015 4:01:09 PM     Aravind
53      1       10/8/2015 4:02:29 PM     Aravind
54      1       12/8/2015 4:03:19 PM     Aravind
55      1       14/8/2015 4:04:39 PM     Aravind
56      1       16/8/2015 4:19:39 PM     Aravind







从上面如果我尝试在访问数据库中使用选择查询,例如






From above if i try to use select query in access db like

Select BMID,UserId,Format([PDate],'dd-MM-yyyy') as PDate1,PName From BodyMeasurements where UserId=1 And BodyMeasurements.[PDate]  between #19/07/2015 12:00:00 AM# and #18/08/2015 11:59:59 PM#





i可以获得所有7行的结果,如果结束日期是2015年8月14日下午11:59:59我可以获得前6行,但如果结束日期是 20年12月8日15 11:59:59 PM我可以得到所有7行结果。



请回复我如果日期为12及以下如何更正值



问候

Aravind



i can get result all 7 rows,if end date is "14/08/2015 11:59:59 PM" i can get top 6 rows,but if end date is "12/08/2015 11:59:59 PM" i can get all 7 rows as result.

pls reply me how to correct values if date is 12 and below

Regards
Aravind

推荐答案

这听起来像Access将你的日期解释为dd第一种情况下为/ mm,第二种情况下为mm / dd。



尝试使用格式yyyy-mm-dd,应始终正确解释。换句话说

This sounds like the Access is interpreting your date as dd/mm in the first case and mm/dd in the second.

Try using format yyyy-mm-dd which should always be interpreted correctly. In other words
Select BMID,UserId,Format([PDate],'dd-MM-yyyy') as PDate1,PName 
From BodyMeasurements 
where UserId=1 
And BodyMeasurements.[PDate]  between #3015-07-19 12:00:00 AM# and #2015-08-18 11:59:59 PM#


这篇关于如何根据vb中的访问db之间的2日期获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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