Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 28th, 2004, 08:51 AM
AgentElmer AgentElmer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 AgentElmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Compare Dates with Different formats

I need to compare dates with possibly different formats. My query is fairly large already. The main point is in red:

SELECT pwl.request_id, pwl.work_list_id, pwl.value
FROM PRODUCT_WORK_LIST pwl, SERVICE_REQUEST sr
WHERE sr.request_id = pwl.request_id
AND (sr.request_status <> 'PND' AND sr.request_status <> 'DEL'
AND sr.request_status <> 'PRG' AND sr.request_status <> 'SUB')
AND pwl.request_id = ANY (
SELECT PRODUCT_WORK_LIST.REQUEST_ID
FROM (CPOT_GROUP INNER JOIN GROUP_TO_PRODUCT ON CPOT_GROUP.ID = GROUP_TO_PRODUCT.GROUP_ID)
INNER JOIN PRODUCT_WORK_LIST ON GROUP_TO_PRODUCT.PRODUCT_ID = PRODUCT_WORK_LIST.PRODUCT_ID
WHERE description = 'Developer'
AND PRODUCT_WORK_LIST.value = to_date('2004-05-19', 'mm/dd/yyyy')
AND work_list_id = 5)
ORDER BY pwl.request_id, pwl.work_list_id;

Reply With Quote
  #2  
Old May 28th, 2004, 10:03 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
What I noticed in your query is that your given date does not comply the format you have defined in the to_date function. also you need to use to_char to convert the date format in the query, as follows:

AND PRODUCT_WORK_LIST.value = to_char('2004-05-19', 'yyyy-mm-dd')

you might still get the problem because your table column PRODUCT_WORK_LIST.value is still using the default date format to compare with formatted date, you need to change the format of table column too in order to keep both values in consistent.

AND to_char(PRODUCT_WORK_LIST.value,'yyyy-mm-dd') = to_char('2004-05-19', 'yyyy-mm-dd')

fixed value need to comply the format defined in the to_char function, but if you are using any table column then you just need to define the format, no matter which format is used to store table column value into table.

Reply With Quote
  #3  
Old May 28th, 2004, 10:49 AM
AgentElmer AgentElmer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 AgentElmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you, that was helpful, but I should have been more clear. What I have now is:

AND to_date(PRODUCT_WORK_LIST.value, 'mm/dd/yyyy') = to_date('2004-05-19', 'yyyy-mm-dd')

The PRODUCT_WORK_LIST.value field is a string, the comparing value is also a string, but this is input by a user. This means I don't know what format the date is going to take (i.e. 'mm-dd-yyyy', 'yyyy-mm-dd', etc). My stored date, however, is a constant format of 'mm/dd/yyyy'. So effectively it will read:

AND to_date(PRODUCT_WORK_LIST.value, 'mm/dd/yyyy') = to_date(userInputString, 'I don't know what format to use')

How can I do this comparison?

Reply With Quote
  #4  
Old June 1st, 2004, 10:44 AM
utecistu utecistu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 16 utecistu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
input mask

You will need an input mask 4 that field. It's not your job 2 find out what date format the user chosen, your job is 2 make sure that the user can only input data based on input mask (field validation) you specified. Minimize your pain and the probability of getting future errors at the user input level. Give him the chance of making a mistake and you can be sure that he will do it. It's like a Murphy law or maybe it is?

Reply With Quote
  #5  
Old June 1st, 2004, 01:58 PM
Kraeg Kraeg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Schaumburg, IL
Posts: 20 Kraeg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not sure if there is a reason your input field is a character field, but you could also set the input field datatype to date, remove all format masks, set the max length to 11 and rely on the os registry settings to convert the date to an acceptable format.

Forms will automatically adjust the date format depending on your max length ('25-may-04' for length 11). Only thing is, not sure how different NLS settings will affect your individual needs.

We do this to allow the users to input almost any way they like. Then to compare we just:

AND to_date(PRODUCT_WORK_LIST.value, 'mm/dd/yyyy') = :input_item

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Compare Dates with Different formats


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway