I'm not sure I follow the question but I did notice the date format mask doesn't match the date string:
To_Date ('01/10/2005', 'dd/mm/yy')
should be
To_Date ('01/10/2005', 'dd/mm/yyyy')
Main Topics
Browse All TopicsGuys
the following code returns information between dates but I want it to return information between exact dates
What I mean is if I have a date range 01/10/05 to 10/10/05 i want it to look at that and not return what is between
ie
if i query from 01/10/05 to 10/10/05 using the formula below it will return 01/10/05 to 09/10/05
dont know why??????
SELECT pol.order_no,
pol.project_id Project,
po.authorize_code Coordinator,
pol.line_no Line,
pol.description,
po.vendor_no Supplier_ID,
s.vendor_name Supplier,
pol.date_entered Order_Date,
pol.wanted_delivery_date Wanted_Delivery_Date,
pol.original_qty * pol.fbuy_unit_price Line_Price,
pol.state,
po.note_id,
substr( ifsapp.Document_Text_API.G
FROM ifsapp.purchase_order po,
ifsapp.purchase_order_line
ifsapp.supplier s
WHERE pol.order_no = po.order_no
AND s.vendor_no = po.vendor_no
--AND pol.line_no = '1'
AND pol.project_id = '90766'
AND pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy') AND To_Date ('12/10/2005', 'dd/mm/yy')
ORDER BY pol.order_no ASC, pol.line_no ASC
can anyone help
Regards
Darren
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>if i query from 01/10/05 to 10/10/05 using the formula below it will return 01/10/05 to 09/10/05
Your date format in the TO_DATE functions is dd/mm/yy - therefore you're asking for dates between Oct 1, 2005 and Oct 10, 2005.
You are getting data between Oct. 1,2005 00:00:00 and Oct. 9, 2005 00:00:00 (where 00:00:00 is the time).
If you want the dates to include Oct 1 and Oct 10, then change to
AND pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy') AND To_Date ('12/10/2005 23:59:59', 'dd/mm/yy hh24:mi:ss')
If you want Oct1 and Oct 10 excluded change to
AND pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy')+1 AND To_Date ('12/10/2005', 'dd/mm/yy')
Sorry.. I meant..
If you want the dates to include Oct 1 and Oct 10, then change to
AND pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy') AND To_Date ('10/10/2005 23:59:59', 'dd/mm/yy hh24:mi:ss')
If you want Oct1 and Oct 10 excluded change to
AND pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy')+1 AND To_Date ('10/10/2005', 'dd/mm/yy')
Assuming that the column: pol.date_entered has a data type of: date, and that the actual values in that column include the time of day, then awking00 is correct. That is, Oracle date columns and variables include a time portion, so when you ask Oracle to return values that are between the dates of: 1-Oct-2005 and 10-Oct-2005, Oracle assumes a time of midnight for both of those dates (since you didn't provide a different time portion) and records that were entered on the 10th, but after midnight (which is probably most or all records for that day) are excluded. You have to use either the extended date/time format that awking00 provided to include the records for later times on the 10th, or if you think there are no records that have a time value of exactly midnight, you could use:
and pol.date_entered BETWEEN To_Date ('01/10/2005', 'dd/mm/yy') AND To_Date ('11/10/2005', 'dd/mm/yy')
That would actually get the records from 1-Oct-2005 (any time of day) through the end of day: 10-Oct-2005. Be careful with this approach though, since if there any records for exactly midnight on the 11th, they would also be included.
Or you could use two separate conditions instead of "between" like this:
and pol.date_entered >= To_Date ('01/10/2005', 'dd/mm/yy')
AND pol.date_entered < To_Date ('11/10/2005', 'dd/mm/yy')
Note that you have to use ">=" for the minimum date (in case there are records for exactly midnight on that day) and "<" for the date one date beyond the date you want included.
DeanHorak,
I think I already said that.
markgeer,
>>Be careful with this approach though, since if there any records for exactly midnight on the 11th, they would also be included.<<
That's why I suggested ...AND to_date('10/10/05 23:59:59','dd/mm/yy hh24:mi:ss')
DarrenJackson,
Actually, I would suggest using ...AND to_date('10/10/2005 23:59:59','dd/mm/rrrr hh24:mi:ss') to avoid any 1905 vs. 2005 type of issues.
Hi,
I have read the posts but after a few ones lost track and intrest. I have ur query modified below try it and let me know if your problem is solved.
==========================
SELECT pol.order_no,
pol.project_id Project,
po.authorize_code Coordinator,
pol.line_no Line,
pol.description,
po.vendor_no Supplier_ID,
s.vendor_name Supplier,
pol.date_entered Order_Date,
pol.wanted_delivery_date Wanted_Delivery_Date,
pol.original_qty * pol.fbuy_unit_price Line_Price,
pol.state,
po.note_id,
substr( ifsapp.Document_Text_API.G
FROM ifsapp.purchase_order po,
ifsapp.purchase_order_line
ifsapp.supplier s
WHERE pol.order_no = po.order_no
AND s.vendor_no = po.vendor_no
--AND pol.line_no = '1'
AND pol.project_id = '90766'
AND trunc(pol.date_entered) BETWEEN To_Date ('01/10/2005', 'dd/mm/yyyy') AND To_Date ('12/10/2005', 'dd/mm/yyyy')
ORDER BY pol.order_no ASC, pol.line_no ASC
==========================
2 changes here
1. change the yy to yyyy
2. use trunc function in pol.date_entered - trunc will give you only the date part in case the data also stores timestamp.
HTH
makhan
Guys
Thankyou all for contributing I am sorry for leaving this for so long but I dont control what projects I work on and sometimes like this one they get away from me.
The problem I had with this was that I was after a query between exact dates what I forgot to realise is that it is not only a date to take into account but the time as this is what has been causing me my grief.
After sepaking to the client their was 1 and simple remedy to this and I was quite surprised they accepted it it was to add a 1 to the dates so that it would capture the missing info.
Sometimes we look to deeply into problems and can be answered very simply. :((
All i can say is thank you all for the assistance and hope that I have not upset anyone over this as I dont like to keep people who are helping me waiting.
What I will do if no one has a objection is split points prorata this way I hope to reward the Experts who stuck with me on this one
once again thankyou
Darren
Business Accounts
Answer for Membership
by: angelIIIPosted on 2005-10-14 at 07:27:06ID: 15085685
what data type is the field pol.date_entered ?
if it is char/varchar, then this would be "normal"