472,354 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Query to search between two dates

omerbutt
638 512MB
i am having an access database and have created a table named RECORDS
which has the following fields

cust_name......(customer name)
items..............(items)
date_pur..........(purchase date)
cmp_name......(company name)

Now i have a form through which i input 2 dates

date_from
date_to

i get these values onto another asp page and i want to search all the records that are between these 2 dates and display them i have no idea for the query to be executed plz plz plz plz if any1 could help me:(
Nov 29 '06 #1
16 25294
NeoPa
32,511 Expert Mod 16PB
I know nothing about ASP.
If you just want a query to do a job then let me know.
Nov 30 '06 #2
omerbutt
638 512MB
yes sir currently my query is
"SELECT * from table_name where field_name>= '"& date_from &"' AND field_name <='"& date_to &"' "

the datatype for the database filed "date_pur" is text i have tried other queries includin the keyword BETWEEN but none of it is giving me the exact results,when i input the dates
date_from=1/1/2006(mm/dd/yyyy)
date_to=8/2/2006(mm/dd/yyyy)

it retrieves correct results but whenever i switch to double figures in the date or month section for example i input the dates
date_from=1/12/2006
date_to=1/22/2006

it gives me the dates that are even smaller than the "date_from" which is not required plz if u can guide me plz doo :( im in aloot mess

tahnks aloot in advance
I know nothing about ASP.
If you just want a query to do a job then let me know.
Dec 4 '06 #3
NeoPa
32,511 Expert Mod 16PB
We can help.
Your SQL is not right.
What is the field type of [Field_Name]?
What is the variable type of Date_From & Date_To?
How is the data put into Date_From & Date_To?
You will need to use the Format() function, but I won't know exactly how without answers to these questions.
Dec 4 '06 #4
NeoPa
32,511 Expert Mod 16PB
Forget last post - I was responding to your SQL which referred to these names but your first post makes it clearer.
Give me some time & I'll get something posted for you.
Dec 4 '06 #5
NeoPa
32,511 Expert Mod 16PB
To set up string variable strSQL with the correct SQL string use :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * " & _
  2.          "FROM [RECORDS] " & _
  3.          "WHERE (CDate(Date_Pur) Between #" & _
  4.          Format(Date_From,"m/d/yyyy") & "# And #" & _
  5.          Format(Date_To,"m/d/yyyy") & "#)"
Dec 4 '06 #6
omerbutt
638 512MB
thanks buddy i wud try it today thankx alooooooooooooooooooot for dat much help thank u ver much and hope to get help in future ;)

To set up string variable strSQL with the correct SQL string use :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * " & _
  2.          "FROM [RECORDS] " & _
  3.          "WHERE (CDate(Date_Pur) Between #" & _
  4.          Format(Date_From,"m/d/yyyy") & "# And #" & _
  5.          Format(Date_To,"m/d/yyyy") & "#)"
Dec 6 '06 #7
NeoPa
32,511 Expert Mod 16PB
No problem - I'm glad you got what you were looking for :).
Dec 6 '06 #8
omerbutt
638 512MB
SIR I AM RECIEN=VING THE ERROR "type mismatch 'format '" :( when i try to run the query now wot:(



No problem - I'm glad you got what you were looking for :).
Dec 8 '06 #9
NeoPa
32,511 Expert Mod 16PB
SIR I AM RECEIVING THE ERROR "type mismatch 'format '" :( when I try to run the query now wot:(
You need to post EXACTLY (sorry to shout ;)) what your code says and let us know where the error message occurred. Last question - What is the type of Date_Pur?
Dec 8 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
"The title of this thread has been changed to make the problem clearer to experts and others searching for similar threads."

MODERATOR
Dec 9 '06 #11
omerbutt
638 512MB
Data type of Date_Pur is "text" and the error is occuring on the query :( if u say so i can copy paste the exact error message here ?



You need to post EXACTLY (sorry to shout ;)) what your code says and let us know where the error message occurred. Last question - What is the type of Date_Pur?
Dec 16 '06 #12
MMcCarthy
14,534 Expert Mod 8TB
Data type of Date_Pur is "text" and the error is occuring on the query :( if u say so i can copy paste the exact error message here ?
I would go ahead and do that

Mary
Dec 16 '06 #13
omerbutt
638 512MB
to make my problem more clear let me tell you that ithe error occours in the query where i am comparing the dates through the 'FORMAT' KEYWORD ...MEANS THE ERROR ORIGINALLY RESIDES ON THE "format" KEYWORD. PLEASE REPLY ME AS SOON AS POSSIBLE i would be very thankfull to you :)

strSQL = "SELECT * " & _
"FROM [RECORDS] " & _
"WHERE (CDate(Date_Pur) Between #" & _
Format(Date_From,"m/d/yyyy") & "# And #" & _
Format(Date_To,"m/d/yyyy") & "#)"

I would go ahead and do that

Mary
Dec 19 '06 #14
MMcCarthy
14,534 Expert Mod 8TB
to make my problem more clear let me tell you that ithe error occours in the query where i am comparing the dates through the 'FORMAT' KEYWORD ...MEANS THE ERROR ORIGINALLY RESIDES ON THE "format" KEYWORD. PLEASE REPLY ME AS SOON AS POSSIBLE i would be very thankfull to you :)

strSQL = "SELECT * " & _
"FROM [RECORDS] " & _
"WHERE (CDate(Date_Pur) Between #" & _
Format(Date_From,"m/d/yyyy") & "# And #" & _
Format(Date_To,"m/d/yyyy") & "#)"
It sounds like Date_Pur is not in a structure that can be read as a date. Can you post a sample of the values in this field.
Dec 19 '06 #15
omerbutt
638 512MB
yeah sure here they are same to same copied from the database filed named"Date_Pur"

Date_Pur
11/2/2006
11/3/2006
11/3/2006
11/3/2005
11/5/2006
11/5/2006
12/1/2006
11/1/2006
11/5/2006
12/2/2006
12/2/2006
12/2/2006
12/2/2006
4/5/2006
11/2/2006
11/1/2006
11/1/2006
11/1/2006
11/2/2006


It sounds like Date_Pur is not in a structure that can be read as a date. Can you post a sample of the values in this field.
Dec 19 '06 #16
NeoPa
32,511 Expert Mod 16PB
These dates look ok.
Can you do a :
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strSQL
after you've set up your strSQL string and before you use it.
Then, using Ctrl-G, Copy and paste the resultant string in here.
Dec 19 '06 #17

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

Similar topics

4
by: Alistair | last post by:
I should just get a hat with a big D on it and then everyone would recognise me.. anyway... I have a DB full of people and their details.. I'm trying to perform a query based on age. so...
3
by: screenwriter776 | last post by:
Hi, folks - Perhaps you could help me with a search form I am building. I have a table with a field in it. I want to return dates inside two parameters the user enters into a search form:...
5
by: Alicia | last post by:
Yes, but will that skip a week and group by the date for me? I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date ...
6
by: kevin carter | last post by:
hi i have a table conataining several fields one of which is date i want to be able to search the table on the date field using code. the code below generates the query from a form, however i get...
5
by: Irfan | last post by:
Hi All, I am trying to create a report but having problem with the critiera selection logic, please help. I have the following fields date1 date2 date3
2
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result....
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
4
by: Stan | last post by:
I am running in ACCESS 2003 a database with a single table. It records service rendered to clients of a food pantry. As each client is served the date is entered into 1-6 fields SvcDate1,...
7
by: shane8960 | last post by:
Hi All, I have a query: SELECT Sum(tbl_ExtrasOrder.OrderExtrasValue) AS SumOfOrderExtrasValue, Sum(tbl_FramesOrder.OrderFramesValue) AS SumOfOrderFramesValue,...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.