在两个日期之间搜索时出现问题 [英] Problem While Searching BetweenTwo Dates

查看:66
本文介绍了在两个日期之间搜索时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友

我正在VB.Net中的一个项目上.我正在使用MS Access作为数据库.
在两个日期之间搜索记录时遇到严重问题.

当我搜索两个日期之间的记录时,它没有给我完整的记录,但是却错过了给定日期之间的某些日期.

我存储日期的MS Access列中的日期格式也是如此.
MS Access中的日期采用"M/d/yyyy"格式.

我使用了两个名为dtpFrom和dtpTo的DateTimePicker.

我已使用以下sql查询在这两个日期之间进行搜索.

Dear Friends

I am working on a project in VB.Net. I am using MS Access as database.
I am having a serious problem while searching the records between two dates.

When I Search the records between two dates it does not give me the complete records but It Missed some of the dates between the given dates.

The Columns in MS Access in which I have stored the dates, is also in date format.
The Dates in MS Access are in "M/d/yyyy" Format.

I have used two DateTimePicker with the name of dtpFrom and dtpTo.

I have used the following sql Query to search between these two dates.

"Select stdnames from tblStudents where AdmDate >= ''" & format((Cdate(dtpFrom.value)),"M/d/yyyy") & "'' and AdmDate <= ''" & format((Cdate(dtpTo.value)),"M/d/yyyy") & "''"



使用此查询,我得到了结果,但是错过了一些日期.因此,我希望获得这两个给定日期之间的所有日期.因此,是否有任何机制可以为我提供给定日期之间的准确日期,而不会遗漏任何日期.

等待响应.



Using This query, I got the result but it missed some of the dates. So, I wan to get all the dates between these two given dates. So, Is there any mechanism that can give me the precise dates between the given dates without missing any of the date.

Waiting for response.

推荐答案

将日期转换为YYYY-MM-DD格式并使用

Convert your dates into YYYY-MM-DD format and use

"Select stdnames from tblStudents where AdmDate >= CDATE(''" & DtFrom & "'') and AdmDate <= cdate(''" & DTTo & "'') "


美国日期格式通常会得出奇怪的结果.

取决于应用到它的搜索,可能会遗漏很多东西,但是使用科学的日期格式应该可以解决问题.
American Date format often gives odd results.

Depending on the search applied to it many things can be missed, but using the scientific date format should negate the problem.


DateTime DT1 = new DateTime();
DT1 = DateTime.Parse(dtpFrom.value);
字符串FrmDate = DT1.ToString("yyyy/MM/dd");

DateTime DT2 =新的DateTime();
DT2 = DateTime.Parse(dtpTo.value);
字符串ToDate = DT2.ToString("yyyy/MM/dd");


从tblStudents中选择stdnames,其中AdmDate> =""&固定日期"和AdmDate< ="&约会与""
DateTime DT1 = new DateTime();
DT1 = DateTime.Parse(dtpFrom.value);
string FrmDate= DT1.ToString("yyyy/MM/dd");

DateTime DT2 = new DateTime();
DT2 = DateTime.Parse(dtpTo.value);
string ToDate= DT2.ToString("yyyy/MM/dd");


"Select stdnames from tblStudents where AdmDate >= ''" & FrmDate & "'' and AdmDate <= ''" & ToDate & "''"


这篇关于在两个日期之间搜索时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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