473,395 Members | 2,010 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 Query

Hello,

Could anyone help me with a query? I have a date field and want to display only
records for a specified month.
Example:
Date:5/12/2004
Query for all records in the month of May, 2004.

Thanks.
Nov 12 '05 #1
4 2284
Kissi5559 wrote:
Hello,

Could anyone help me with a query? I have a date field and want to
display only records for a specified month.
Example:
Date:5/12/2004
Query for all records in the month of May, 2004.

Thanks.


Build a query and enter a "field"...

DateMonth: Month([MyDateField])

Add criteria "5"

and another field...

DateYear: Year([MyDateField])

With criteria "2004"

OR.........

DateFilter: Month([MyDateField]) = 5 And Year([MyDateField]) = 2004

and then set theCriteria to "True"

OR.........

Select your date field and add the criteria.... (US dates)

Between #05/01/2004# And #05/30/2004#

There's lots of different ways... :)
--
regards,

Bradley
Nov 12 '05 #2
Bradley wrote:
Kissi5559 wrote:
Hello,

Could anyone help me with a query? I have a date field and want to
display only records for a specified month.
Example:
Date:5/12/2004
Query for all records in the month of May, 2004.

Thanks.

Build a query and enter a "field"...

DateMonth: Month([MyDateField])

Add criteria "5"

and another field...

DateYear: Year([MyDateField])

With criteria "2004"

OR.........

DateFilter: Month([MyDateField]) = 5 And Year([MyDateField]) = 2004

and then set theCriteria to "True"

OR.........

Select your date field and add the criteria.... (US dates)

Between #05/01/2004# And #05/30/2004#

There's lots of different ways... :)


The between will be faster as it won't need to run two functions on each
record during select and also if the date field is indexed it will use
it. It's worth noting that if you use dates in a form and reference
those, e.g. between forms!MyForm!MyDate1 and forms!MyForm!MyDate2 then
the dates will be in the country format specified by windows, same if
you put the dates into the query grid but must be in US format in a SQL
literal string.

Oh BTW Bradley, May has 31 days :-)

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 12 '05 #3
Bradley wrote:
Between #05/01/2004# And #05/30/2004#

There's lots of different ways... :)


Another thing, your dates may have times on so:

Between #05/01/2004# And #05/30/2004 23:59:59#

or

QueryDate >= #05/01/2004# And QueryDate < #06/01/2004#

I prefer the latter as it's more explicit, to the uninitiated it's not
clear whether "between" actually includes the dates you're looking at.
If you think about it, if you drive your car between two posts, do you
want to hit the posts?

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 12 '05 #4
Trevor Best wrote:
Bradley wrote:
Kissi5559 wrote:
Hello,

Could anyone help me with a query? I have a date field and want to
display only records for a specified month.
Example:
Date:5/12/2004
Query for all records in the month of May, 2004.

Thanks.

Build a query and enter a "field"...

DateMonth: Month([MyDateField])

Add criteria "5"

and another field...

DateYear: Year([MyDateField])

With criteria "2004"

OR.........

DateFilter: Month([MyDateField]) = 5 And Year([MyDateField]) = 2004

and then set theCriteria to "True"

OR.........

Select your date field and add the criteria.... (US dates)

Between #05/01/2004# And #05/30/2004#

There's lots of different ways... :)


The between will be faster as it won't need to run two functions on
each record during select and also if the date field is indexed it
will use it. It's worth noting that if you use dates in a form and
reference those, e.g. between forms!MyForm!MyDate1 and
forms!MyForm!MyDate2 then the dates will be in the country format
specified by windows, same if you put the dates into the query grid
but must be in US format in a SQL literal string.


Gereral rule is if you are building an SQL string manually or a where
clause in code (or in a property value?), use US dates (?)
Oh BTW Bradley, May has 31 days :-)


I wondered that when I posted.. probably why I don't use that method
often ;) Usually I will know the month and year so using the between
method would require working out the end of month date so I figure might
as well use Month() and Year() in some applications.
--
regards,

Bradley
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
2
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
4
by: Peter Bailey | last post by:
I have a vba string taht dynamically creates the query which has two dates in it that it grabs off an open form as a string from the textbox. What I generate in vba is: SELECT DOSMBK.Date,...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
11
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.