473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

date range for report query

Hello all,

I have a timesheet details table . I am trying to run the following query against it.
Expand|Select|Wrap|Line Numbers
  1. SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
  2. FROM timesheetdetails
  3. WHERE Format([date],'dd/mm/yyyy') between '01/01/2007' and '01/12/2007';
  4.  
There is data in the table corresponding to all months. This query returns nothing.

Very strangely, the lower condition works. For example, if I change the query to
Expand|Select|Wrap|Line Numbers
  1. SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
  2. FROM timesheetdetails
  3. WHERE Format([date],'dd/mm/yyyy') >= '01/01/2007' ;
  4.  
then I get all the records. But the inute I put in an upper boundary , for example

Expand|Select|Wrap|Line Numbers
  1. SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
  2. FROM timesheetdetails
  3. WHERE Format([date],'dd/mm/yyyy') >= '01/01/2007' and 
  4. Format([date],'dd/mm/yyyy') <= '01/01/2008' ;
  5.  
I get no records.

Please help me. I need this urgently for a report. I have searched this site ad also the web for solutions. the syntax for the query is correct. why doesnt it work?

Thanks in advance
Nanda
Aug 14 '07 #1
1 1560
FishVal
2,653 Expert 2GB
Hello all,

I have a timesheet details table . I am trying to run the following query against it.
SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
FROM timesheetdetails
WHERE Format([date],'dd/mm/yyyy') between '01/01/2007' and '01/12/2007';

There is data in the table corresponding to all months. This query returns nothing.

Very strangely, the lower condition works. For example, if I change the query to
SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
FROM timesheetdetails
WHERE Format([date],'dd/mm/yyyy') >= '01/01/2007' ;

then I get all the records. But the inute I put in an upper boundary , for example

SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
FROM timesheetdetails
WHERE Format([date],'dd/mm/yyyy') >= '01/01/2007' and
Format([date],'dd/mm/yyyy') <= '01/01/2008' ;

I get no records.

Please help me. I need this urgently for a report. I have searched this site ad also the web for solutions. the syntax for the query is correct. why doesnt it work?

Thanks in advance
Nanda
Hi, Nanda.

You try to compare dates as strings but the rules of string comparing are quite different then that for dates.
Example

? "01/01/2007" > "02/01/2001"
False
? #01/01/2007# > #02/01/2001#
True

What's wrong with direct date comparing?

Expand|Select|Wrap|Line Numbers
  1. SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
  2. FROM timesheetdetails
  3. WHERE [date] between #01/01/2007# and #12/01/2007#;
  4.  
or

Expand|Select|Wrap|Line Numbers
  1. SELECT [timesheetdetails].[Timesheetid], [timesheetdetails].[Totalhours]
  2. FROM timesheetdetails
  3. WHERE Year([date]) = 2007;
  4.  
or if you input date somewhere in form/dialog in dd/mm/yyyy format you may need to use DateSerial function to return date value

Anyway particular solution depends on how do you get criteria dates, in what format and how do you pass them to the query.
Aug 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: BlackFireNova | last post by:
Using Access 2002 I am writing a report which draws data from several different tables. I can't link all the tables in a query, as some can not be related without truncating the data. I plan...
2
by: david.isaacks | last post by:
I have a table with an as a field with the date/time in it. Formated like "3/20/2006 7:25:00 AM" I want to be able to create a query for just the dates in Feb, March, April, etc.. I do want to...
10
Cyberdyne
by: Cyberdyne | last post by:
Here is the problem, I have a form with a field named Occurence with a Short Date Value, once entered it subsequently appears in 3 fields SOL1 which adds one year, SOL2 which adds 2 years and...
6
by: delsay | last post by:
I am attempting to create a query that creates a Count for each month and year combo starting in 1992 (Jan 1992, Feb 1992). The field Purchase Date contains dates that are in the Date/Time format. ...
1
by: irfanali | last post by:
Hallo All, This is a Tool i m tryin to develop at work. I will explain how it works and then the Q I download a report from my ERP Tool on a daily basis and upload it into the Access Tool....
19
by: ali3n8 | last post by:
Hello I have attempted to create a date range report from a query called qrycustomerinformation. The field that contains the value of my date is called Followup. When i run a report on this it is...
1
by: kappa | last post by:
I have a problem in ALL my queries when I run a specific date range. Access always crashes when I view in Datasheet view. This doesn't occur if it's a parameter query and I am prompted to enter the...
3
by: kmnotes04 | last post by:
Could anyone tell me how to restrict the date range for items that appear on a report? Old items from previous years appear on the report. I was asked to have only this year's items (and beyond)...
4
by: rekhasc | last post by:
hi friends.. i am using sql server 2005 reporting services.. in database the table contains startdate row and enddate row... i want the query which display all the contents between these...
2
by: Lisa B | last post by:
I have managed to create a Report from a form that displays data per date In the query criteria for the date it references the form !! The report is based on the results of the query as per...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.