Advertisement

10.14.2005 at 07:25AM PDT, ID: 21595167
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

between dates function in sql

Tags: between, date
Guys

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.Get_All_Notes(po.note_id,'6'),1,2000) Text
FROM ifsapp.purchase_order po,
     ifsapp.purchase_order_line_all pol,
     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
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: DarrenJackson
Solution Provided By: markgeer
Participating Experts: 8
Solution Grade: A
Views: 1161
Translate:
Loading Advertisement...
10.14.2005 at 07:27AM PDT, ID: 15085685

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:27AM PDT, ID: 15085693

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:29AM PDT, ID: 15085703

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:32AM PDT, ID: 15085734

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:34AM PDT, ID: 15085759

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:36AM PDT, ID: 15085775

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:37AM PDT, ID: 15085788

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:41AM PDT, ID: 15085819

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:42AM PDT, ID: 15085834

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:49AM PDT, ID: 15085894

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:50AM PDT, ID: 15085905

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 07:52AM PDT, ID: 15085931

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 08:01AM PDT, ID: 15086023

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 08:14AM PDT, ID: 15086123

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.14.2005 at 11:57PM PDT, ID: 15090485

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.24.2005 at 09:07AM PST, ID: 15357446

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.24.2005 at 11:33PM PST, ID: 15359475

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
10.14.2005 at 07:27AM PDT, ID: 15085685

Rank: Genius

what data type is the field  pol.date_entered ?
if it is char/varchar, then this would be "normal"
 
10.14.2005 at 07:27AM PDT, ID: 15085693

Rank: Sage

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')
 
10.14.2005 at 07:29AM PDT, ID: 15085703

Rank: Sage

Then you need

AND pol.date_entered IN(To_Date ('01/10/2005', 'dd/mm/yy') ,To_Date ('10/10/2005', 'dd/mm/yy'))
 
10.14.2005 at 07:32AM PDT, ID: 15085734

Rank: Guru

The problem is that when you say to_date('10/10/05','dd/mm/yy'), you are really saying one minute after 11:59 p.m. on 10/09/05. You can use

between to_date('01/01/05','dd/mm/yy') and to_date('10/10/05 23:59:59','dd/mm/yy hh:mi:ss')
 
10.14.2005 at 07:34AM PDT, ID: 15085759

Rank: Guru

Oops! Missed 24 hour clock usage.

between to_date('01/01/05','dd/mm/yy') and to_date('10/10/05 23:59:59','dd/mm/yy hh24:mi:ss')
 
10.14.2005 at 07:36AM PDT, ID: 15085775

Rank: Sage

>> between to_date('01/01/05','dd/mm/yy') and to_date('10/10/05 23:59:59','dd/mm/yy hh:mi:ss')

doesnt matter, If i'm not mistaken BETWEEN means >= and <= and not > and <
 
10.14.2005 at 07:37AM PDT, ID: 15085788

Rank: Sage

I think the question is not very clear but I feel the answer by paquicuba is meant to solve it!!

Just an alternative to this solution, you can use this also,

AND (pol.date_entered = To_Date ('01/10/2005', 'dd/mm/yy')  OR pol.date_entered = To_Date ('10/10/2005', 'dd/mm/yy'))
Assisted Solution
 
10.14.2005 at 07:41AM PDT, ID: 15085819
>>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')

 
10.14.2005 at 07:42AM PDT, ID: 15085834
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')

Assisted Solution
 
10.14.2005 at 07:49AM PDT, ID: 15085894

Rank: Genius

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.
Accepted Solution
 
10.14.2005 at 07:50AM PDT, ID: 15085905
bloody hell just gone away for 5mins and flood gates have opened

Thank you all for your posts

just to answer some questions the field type is date

also i noticed the formatting with the extra "dd/mm/    yyyy       " but that is not the answer

I am trying the rest will come back shortly

cheers

Darren
 
10.14.2005 at 07:52AM PDT, ID: 15085931

Rank: Sage

>>bloody hell just gone away for 5mins and flood gates have opened

asked by DarrenJackson on 10/14/2005 08:25AM MDT
Comment from markgeer Date: 10/14/2005 08:49AM MDT

25 mins!!
 
10.14.2005 at 08:01AM PDT, ID: 15086023

Rank: Guru

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.
Assisted Solution
 
10.14.2005 at 08:14AM PDT, ID: 15086123
>>I think I already said that.

Yes you did. I just didn't refresh before my post (as it took a few minutes to put together the post) - I try to be as explanitory as possible in my answers....
 
10.14.2005 at 11:57PM PDT, ID: 15090485
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.Get_All_Notes(po.note_id,'6'),1,2000) Text
FROM ifsapp.purchase_order po,
     ifsapp.purchase_order_line_all pol,
     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
Assisted Solution
 
11.24.2005 at 09:07AM PST, ID: 15357446
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
 
11.24.2005 at 11:33PM PST, ID: 15359475
Darren

I you should have taken my suggestion of trunc() function which would have given you only the date without the time field.

Would have saved you lot of trouble. In fact I did not elaborate on this function was my mistake. :)

Regards,

makhan.
 
 
20080236-EE-VQP-29