Click here to Skip to main content
12,954,203 members (52,442 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I m using C# in VS2008 and MS Access 2003 Data Base to develop the windows application
Now i am building a SQL query to get record between two dates form ACCEss database. but problem is that i m not getting proper result.
I am using following query :

the table field is datetime.

sql="Select * From TABLE where datefield between #04/04/2011#
and #09/05/2011#";
i m using dataadapter and dataset to fill records.
but this query show result till 05/09/2011 instead of 09/05/2011.
I have try to search google but no precise solution found...
please help..its urgent..........
Posted 5-Feb-13 21:17pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

AS you can see in your first datetime parameter because 04/04 is the same it seems correct but is wrong as well. So you are having issues with the datetime due to the formatting of the date. You should use:
Format(YourDateParam, "yyyy/MM/dd hh:mm:ss tt")
Access needs an unambiguous date.
You might like to remove the time element as well.
better use parameterized queries[^] so it will be automatically formatted to the proper datetime.

Good luck,
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

use Date object & pass it to query it will work fine

Date start =new Date();
Date End =new Date();
sql="Select * From TABLE where datefield between '"+start+"' 
and '"+End+"'";

will work fine
PunithaSabareeswari 6-Feb-13 5:28am
This won't display correctly... to kandarp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100