473,385 Members | 1,292 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,385 software developers and data experts.

Complex date query, Suggestions please

I need to set up a query that will pick out records for the current winter
season.

I.e., each season runs from October 1 until March 31. The catch is, the year
can't be hard coded. So, if the query is run on September 30 of this year
(2006) it should show all records with a date between October 1, 2005 and
March 31, 2006. If that same query is run on October 1, 2006 it should show
all records with a date from October 1, 2006 through March 31, 2007. This
would then perpetuate each year. Any suggestions on where to begin?
Nov 8 '06 #1
3 1720
Robert wrote:
I need to set up a query that will pick out records for the current winter
season.

I.e., each season runs from October 1 until March 31. The catch is, the year
can't be hard coded. So, if the query is run on September 30 of this year
(2006) it should show all records with a date between October 1, 2005 and
March 31, 2006. If that same query is run on October 1, 2006 it should show
all records with a date from October 1, 2006 through March 31, 2007. This
would then perpetuate each year. Any suggestions on where to begin?
I would use something like:

SELECT * FROM MyTable WHERE DateValue(TimeStamp) BETWEEN
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")), 10, 1) AND
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")) + 1, 3, 31);

James A. Fortune
CD********@FortuneJames.com

Nov 8 '06 #2

<CD********@FortuneJames.comwrote in message
>
I would use something like:

SELECT * FROM MyTable WHERE DateValue(TimeStamp) BETWEEN
What is TimeStamp? Access didn't recognize it as a built in function so I'm
assuming it refers to the current date, thus using Date() in its place would
accomplish the same thing?

Also, when I used the query as written (replacing TimeStamp with Date() )
the results include all entries in the table.
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")), 10, 1) AND
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")) + 1, 3, 31);

James A. Fortune
CD********@FortuneJames.com

Nov 10 '06 #3
Jimmy wrote:
<CD********@FortuneJames.comwrote in message

I would use something like:

SELECT * FROM MyTable WHERE DateValue(TimeStamp) BETWEEN

What is TimeStamp? Access didn't recognize it as a built in function so I'm
assuming it refers to the current date, thus using Date() in its place would
accomplish the same thing?

Also, when I used the query as written (replacing TimeStamp with Date() )
the results include all entries in the table.
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")), 10, 1) AND
DateSerial(Year(Date()) + Int(Format(Date(), "yyyy.mmdd") -
Format(DateSerial(Year(Date()), 10, 1), "yyyy.mmdd")) + 1, 3, 31);

James A. Fortune
CD********@FortuneJames.com
You said:

"it should show all records with a date between October 1, 2005 and
March 31, 2006"

You didn't indicate the field name you use for this date so I used a
field called TimeStamp in place of your field.

James A. Fortune
CD********@FortuneJames.com

Nov 10 '06 #4

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

Similar topics

7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
4
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to...
5
by: Javier | last post by:
I have a field type Date/Time that automatically defaults to Now(). I'm having a problem writing a query that will retrieve all the records for a specific date the user to enters when prompted. I...
5
by: 肥權 | last post by:
Hi everybody, I have a table storing the quiz data of the students like this: Date | Time | Name | Grade I can show the data of specific student by the query below: SELECT * FROM tbl_quiz
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
3
by: Wired Hosting News | last post by:
Lets say I have 10 products in 10 different stores and every week I get a report from each store telling me how many items they have left for each of the 10 products. So each week I enter in 100...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
1
by: Rudolf Bargholz | last post by:
Hi, We have created triggers to log modifications to tables in our application. The triggers work fine, just on one of the tables in our database the triggers fail with the error message...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...

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.