Oracle date field not comparing properly with to_date function

Hi, i'm facing a very weird problem. I'm triyng to retrieve a range of records in between two dates. However, it doesn't seem to understand. What am i doing wrong?
let's say my table (MYRECORD) has this (where id is varchar and date is DATE and not timestamp) :
ID DATE
1 22-JAN-08
2 22-JAN-08
3 21-JAN-10
4 11-FEB-10
5 11-FEB-10
So, let's say iwanna get the records from 21st Jan 2010 :
select
date as ori_date from MYRECORD where
date = to_date('21/01/2010','DD/MM/YYYY')
1.)
it is not returning any record at all. I'm having problems with between dates and the to_date function as well,
so i'm trying to get the 'equal' part working first. I can't use to_char because at the end of the day,
i need to compare between dates.
what am i doing wrong? has this got anything to do with what kind of format is set up on the oracle server?
running :
SELECT value FROM v$nls_parameters WHERE parameter ='NLS_DATE_FORMAT'
returns DD-MON-RR
2.) how do we compare dates from the table according to our own specified format from our passed string? I only have READONLY access to this database
so i can't set anything up.

please run this
select To_date(date, 'DD/MM/YYYY HH24:MI:SS') as ori_date from MYRECORDprobably you have hour minute second info in your table, to_date('01012010','DDMMYYYY') means hour, minute and second is 00:00:00 so it wont be equal.The database field type is actually 'DATE' and not datetime. I've also ran the sql you provided to show its timestamp, but it's not showing anything as far as timestamp is concerned. It's showing only the date. So does this mean it's a real date only information?
However, it might be more efficient to do two comparisons, especially if there's an index on dt:
WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
AND     dt <  TO_DATE ('22/01/2010', 'DD/MM/YYYY')
Ok. If we change the range to compare it on the same day, it won't work;
WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
AND     dt <=  TO_DATE ('21/01/2010', 'DD/MM/YYYY')this also happens if we're using BETWEEN
this is real weird. It's supposed to work...i don't recall having this kind of issue on other databases. If that's the case,
each time a user passes me a date string i have to somehow add another day onto its 'to' comparison date in order for things to work.
but..i don't want to since i don't want to accidentally include the extra day's results!
Edited by: 803998 on Oct 21, 2010 8:14 PM
Edited by: 803998 on Oct 21, 2010 8:33 PM

Similar Messages

  • Dense_Rank() over order by date fields not working properly

    Hi,
    i have a pl/sql statement which looks like this:
    WITH OrderedByDateTable     AS
         SELECT     gsp.*, DENSE_RANK () OVER (ORDER BY A_varChar_col1,
    decode(upper('COMPLIANCETICKSDATE'),'TASKNBR',TASK_NBR,
    'DESCRIPTION', DESCRIPTION,
    'PARTNBR', PART_NBR,
    'PARTSERIALNBR', PART_SERIAL_NBR,
    'SORTDATE', TO_DATE(MIN_EST_DUE_DATE),
    'COMPLIANCETICKSDATE', COMPLIANCE_DATE,
    TASK_NBR
    )DESC NULLS LAST,task_nbr,description,enrtask_id)     AS r_num
         FROM     GT_STATUS_PAGING gsp
    SELECT     *
    FROM     OrderedByDateTable     
    The result that i am expecting is that the dense_rank should order the compliance_date column in desc order and finally gives ranks to the rows.
    But i am getting the resultset in some order all the time, but it is neither ASC or DESC.
    But if for debugging purposes, lets say if i replace the COMPLIANCE_DATE column with DESCRIPTION column again it works perfectly fine giving me the descriptions in DESC order along with the ranks. But for both the date fields above it doesnt work.
    Can anyone please help me on how to solve this?

    user12270778 wrote:
    Hi,
    i have a pl/sql statement which looks like this:
    The result that i am expecting is that the dense_rank should order the compliance_date column in desc order and finally gives ranks to the rows.
    But i am getting the resultset in some order all the time, but it is neither ASC or DESC.
    Can anyone please help me on how to solve this?The problem is an implicit date conversion that takes place.
    Because the first parameters of your decode are strings, the COMPLIANCE_DATE column is also converted into a string. This string is then sorted alphanumerically. The default format mask is often DD-MON-RR. Therefore your date column would be sorted by day, then by the name of the month and so on.
    Fast solution would be to do an explicit conversion from date into strings that match the ordering.
    WITH  OrderedByDateTable     AS
            (     SELECT     gsp.*, DENSE_RANK () OVER (ORDER BY  A_varChar_col1,
                         decode(upper('COMPLIANCETICKSDATE'),
                                   'TASKNBR',TASK_NBR,
                                   'DESCRIPTION', DESCRIPTION,
                                   'PARTNBR', PART_NBR,
                                   'PARTSERIALNBR', PART_SERIAL_NBR,
                                   'SORTDATE', TO_DATE(MIN_EST_DUE_DATE),
                                   'COMPLIANCETICKSDATE', to_char(COMPLIANCE_DATE,'YYYYMMDD HH24:MI:SS'), /* this is the important bit */
                                   TASK_NBR
                                   ) DESC NULLS LAST,task_nbr,description,enrtask_id)     AS r_num
                        FROM     GT_STATUS_PAGING  gsp
    SELECT     *
    FROM     OrderedByDateTable     You should be careful, because the same problem also happens with your SORTDATE column MIN_EST_DUE_DATE.
    Edited by: Sven W. on Oct 25, 2012 6:53 PM

  • Date fields and compare and get the later date of the fields

    I am trying to compare these date fields and compare and get the later date of the fields
    Tables are
    TABCASER
    TABCASER1
    EVCASERS
    Field
    Are
    TABCASER1.CASER_no
    The dates are to be compared and then get the records with the highest or latest date value.
    TABCASER1.CASERRECIEVEDDATE
    EVCASERS.FINALEVDATES
    EVCASERS.PUBLICATIONDATE
    EVCASERS.PUBLICATIONDATE
    TABCASER.COMPAREACCEPDATE
    I have this code but I am trying to figure out what it all means.
    I have several questions.
    1.
    1.     greatest it is used here to compare right? How do I then output this ? do I store it to a var (coldfusion) ultimately , I wish to send it to a page of records
    2.     is it necessary to use todate? And to_date? What does this do?
    3.     decode, is this necessary too. What does this do? NULL?
    4.     
    5.     
    6.     when I do get the query results how do I send it to coldsuion and out put to a display.
    Someone sent me this code.
    is there abetter way of doing this? To compare the dates and store in a var to display. thanks
    Here is my code below:
    Greatest(
         CASE
              WHEN INSTR(TABCASER1.CASER_no,'-CE') > 0 THEN
         decode(TABCASER1.CASERRECIEVEDDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER1.CASERRECIEVEDDATE)
                             WHEN INSTR(TABCASER1.CASER_no,'-ERNIE') > 0 THEN
         decode(EVCASERS.FINALEVDATES,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.FINALEVDATES)
                             WHEN INSTR(TABCASER1.CASER_no,'-MONIE') > 0 THEN
         decode(EVCASERS.PUBLICATIONDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.PUBLICATIONDATE)
                             WHEN INSTR(TABCASER1.CASER_no,'-NADINE') > 0 THEN
         decode(EVCASERS.PUBLICATIONDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.PUBLICATIONDATE)
                             ELSE
         decode(TABCASER.COMPAREACCEPDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER.COMPAREACCEPDATE)
                        END
              ,decode(TABCASER.COMPAREACCEPDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER.COMPAREACCEPDATE))
              between TO_DATE('#dateformat(form.startDate,"mm/dd/yyyy")#','MM/DD/YYYY') and TO_DATE('#dateformat(form.endDate,"mm/dd/yyyy")#','MM/DD/YYYY')
    is there abetter way of doing this? To compare the dates and store in a var to display. thanks

    Hi
    If you have date datatypes than:
    select
    greatest(TABCASER1.CASERRECIEVEDDATE, EVCASERS.FINALEVDATES, EVCASERS.PUBLICATIONDATE, EVCASERS.PUBLICATIONDATE, TABCASER.COMPAREACCEPDATE)
    from TABCASER, TABCASER1, EVCASERS
    where ...-- join and other conditions
    1. greatest is good enough
    2. to_date creates date dataype from string with the format of format string ('mm/dd/yyyy')
    3. decode(a, b, c, d) is a function: if a = b than return c else d. NULL means that there is no data in the cell of the table.
    6. to format the date for display use to_char function with format modell as in the to_date function.
    Ott Karesz
    http://www.trendo-kft.hu

  • Oracle 11g jars not being compatible with WAS 6.1.x versions

    Hi,
    We have an issue with Oracle 11g jars not being compatible with WAS 6.1.x versions.
    If we use Oracle10g client jars then they are working with the 11g database.
    Below are the findings
    Working fine With Ojdbc14.jar
    Not working With Ojdbc5.jar
    WAS 6.0
    Working fine With Ojdbc14.jar
    Not working With Ojdbc5.jar
    WAS 6.013
    Working fine With Ojdbc14.jar
    Not working With Ojdbc5.jar
    As per IBM website link Oracle 11g should be working with WAS 6.1.0.21 upwards
    Could somebody please help me regarding the same.
    thanks & Regards,
    Anoop

    # Download the full Firefox installer from http://www.mozilla.com/
    # Delete the Firefox [http://kb.mozillazine.org/Installation_directory installation directory], making sure all the Firefox files and folders are removed. The default location on 32 bit Windows is C:\Program Files\Mozilla Firefox\
    # Re-install Firefox
    Note that deleting the Firefox installation directory will not remove your bookmarks or other Firefox user data, they are stored elsewhere.

  • Time/Date Field Not Returned in PDF

    I have created a very simple form in LiveCycle Designer 8.0. The form enables the user to input data into columns labeled "name," "change type," and "change date." I used the date/time object for the "change date" row fields.
    When my testers (using Acrobat 7.0) email the saved form back to me, all of the fields are populated with the information they entered, except the "change date" column fields. I asked if they used the flyout calendar or typed in the date manually, and all used the calendar.
    Is this a compatibility issue, or is there something I need to do to bind the chose value to the field when the form is saved?

    The issue with the time portion of date field not displaying in Data tab of a Table window has been posted before - see date format while browsing data
    I still get the problem in v1215 connecting to either 9i or 10g databases. Note that this problem does not happen in the SQL Worksheet results area, so simply querying the table data with a select doesn't test this.
    As for Ctrl-C, Ctrl-V changing the date format to MM/DD/YYYY HH24:MI:SS when copying data out of the SQL Worksheet Results - I also still get this in v1215.

  • How to convert SAP dateTime field to Oracle date field

    Hi All,
                We have a scenario where the incoming data is in the following format:
    < ReconciliationData >
        < RowID > 9 </ RowID > 
        < Run_ID > 7 </ Run_ID > 
        < Control_ID > 5.40 </ Control_ID > 
        < Control_Name > MTD CHARGES TO CARP ORDERS INVENTORY </ Control_Name > 
        < Start_Month > 008 </ Start_Month > 
        < End_Month > 008 </ End_Month > 
    <b>   < SAP_Time > 20070828190545 </ SAP_Time > </b>
        < SAP_Count > 4 </ SAP_Count > 
        < SAP_Amount > 5000.00 </ SAP_Amount > 
        </ ReconciliationData >
    On the receiver side is oracle database. SAP TIME field has to go into Oracle Date field. it should be transformed to structure yyyy/mm/dd hh:mm:ss format.
    How do i go about doing it?
    Regards,
    XIer

    hey
    did u try the DateTrans function?if that does not work then u can write a simple UDF for it
    http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/frameset.htm
    Thanx
    Aamir

  • Contacts on my iphone does not sync properly with icloud.

    Contacts on my iphone does not sync properly with icloud. I have merged data with facebook contacts, and this merged information appears as I want it to be on icloud.com. But on the iphone, the facebook contacts and the icloud contact appear separately.
    I have tried exporting the contacts out of icloud.com, then deleting all contacts on both icloud.com and on the iphone; then importing the vcard back into icloud.com, but the facebook details still appear as a separate contact. It is too time consuming to merge all of my contacts manually What should I do in order for the iphone to display the contacts as it is on icloud.com?

    Is there some sort of Facebook tag on the vCard?

  • Remote not working properly with Apple TV...sporadic fuctioning

    Hello,
    I have no idea what caused this to happen, but both my remotes (I have one from my MacBook Pro and one from my AppleTV) seem to not work properly with AppleTV. It sometimes works but it is extremely frustrating as it only registers about 1 out of every 10-20 clicks then continues to remember the previous clicks therefore making it essentially impossible to select the desired menu/item. Basically it just seems like it's out of control!
    I tested whether it was the remote or AppleTV that was causing the problem by running Front Row on my MacBook Pro and both remotes seem to navigate Front Row perfectly fine. They both act the same way with AppleTV, whether they are paired or not. It seems as though something happened with my AppleTV. This problem occurred randomly, with no specific cause I can think of.
    Please let me know if any of you have ever experienced this problem and what your solution was, if any!
    I have tried restoring to factory conditions, resetting settings, ran diagnostics, unplugged and replugged it, and nothing seems to be working!
    Oh, and I just replaced the battery on one and have tried swapping batteries, etc.
    HELP PLEASE!
    Thank you,
    Travis

    The menus have never been as responsive as they used to since the 2.0 update in my opinion - basically AppleTV seems to cache/buffer remote click if it is busy or perhaps waiting for something to stream from itunes, and when resources become available it suddenly executes all command rapidly which makes it behave wildly in menus.
    Usually happens I find after restarting the unit or if streaming drives have gone in to power saving modes and there's a delay while they wake up to feed the AppleTV.

  • HP computer will not work properly with an HP printer

    I have the following two items that I am trying to use together:
     - HP 23" TouchSmart Desktop, T6500 2.1GHz 4GB DDR3, 500GB HDD (Windows 7)
     - HP OfficeJet 6500 Multi-Function Printer/Scanner/Fax
    When I try to scan to Adobe Acrobat Professional 9.0, the document goes through the scanner, however the dialog box that I would expect (e.g. "Next Page" or "Done") never shows up.  At this point, the system is unresponsive with respect to Adobe or the printer.
    I suspect that it is waiting for the input from the dialog box that never showed up.  I tried to move the other windows to see if the dialog opened in the background, however I am not able to select any of them (they remain frozen).
    I contacted HP Support, only to have them tell me it must be the driver, and I have an "old" printer.  (I did not realize that a 9 month old printer was considered "old").  I have tried all of the possible drivers that are available (original disk, downloads, other downloads from HP tech support), none of these resolves the problem.
    In any case, they were unable to resolve the problem of having an HP computer work properly with an HP printer.  (The printing function seems to work, just very slowly).
    Has anyone else heard of this?  Is there a resolution?

    Update: I am still looking for a solution to this problem - the scanning portion of the Multi-function OfficeJet 6500 does not work properly with the HP TouchSmart computer.
    I have not been able to find anyone in HP that can tell me when (or if) new drivers will be released for this printer.
    I decided to investigate upgrading to a newer version of printer since HP told me the 9 month old printer I have was "obsolete", only to find that the identical printer is still on sale in many stores.  Hmmm....
    I feel like I am getting the run-around from HP.
    I have since tried several more driver/software combinations, but every time I have the same problem (as described in the previous post).
    If anyone has any ideas or suggestions, I would be most happy to hear them.
    Thank you.

  • Help, web cam is not working properly with win vista

    Hii.. my web cam is not working properly with win vista..even if the icon appears bt it does nt start.. its
    lenovo easy capture 2.5...so if u cud suggest me anything...
    Moderator note; subject edited

    re-install drivers and try again. ( also easy capture )

  • FW CS6 Align tool not working properly with lines of text

    Much to my surprise the align tool is not aligning properly with text and I'm not sure what the issue is. My snap to grid distance is set at 1 in preferences.
    Task: Left-align several vertically-stacked lines of type using the alignment tool. All lines have text-align: left.
    Result: Some of lines of type display 1px off from each other. Using the right-align tool yields the same issue.
    Oddly enough shapes align pixel-perfect.
    Any ideas? Thanks!

    I'm not certain of this, but I believe the Align panel aligns the text runs as opposed to the text boxes themselves. This should be a good thing, as it's usually the text that needs to be aligned, not the invisible boxes containing the text.
    Could that be what's happening?

  • My iPad is not syncing properly with my calendar on my computer.  Everything is a day off on the IPad.  Any suggestions?

    My iPad calendar is not syncing properly with my computer.  Everything in the iPad Calendar is one day off....any suggestions?

    Susan,
    Also note that the calender can be set to preserve a time zone by going to Settings > Mail, Contacts, Calendars and turning ON Time Zone Support - but then your flight times will be correct for the local time zone...found that one while on travel and the calender was showing a flight time that was an hour earlier than I thought it was.  I had not turned on Time Zone support and it moved the time I had entered at home to the time of the local zone.
    Convenient as long as you pay attention

  • Hi, My iPhone 4s does not work properly with the sound.

    Hi, My iPhone 4s does not work properly with the sound. It just ring. Any other app it doesn't make sound unless I have my headset or bluetooth. And it make me choose between "DOCK CONECTOR" or my "APPLE TV". Why? Or any sugestion plz

    Hi M3MB3R,
    Thanks for visiting Apple Support Communities.
    You may find the troubleshooting tips in this article helpful:
    iPhone: Sound muffled or low from the speaker or when speaking into the mic
    http://support.apple.com/kb/TS1631
    Cheers,
    Jeremy

  • My iphone 5 does not work properly with Ford Sync,

    Hi, My iphone 5 does not work properly with Ford Sync, everytime I pair the phone, Ford sync navigation system freezes and does not work !
    Can someone help.

    Hi M3MB3R,
    Thanks for visiting Apple Support Communities.
    You may find the troubleshooting tips in this article helpful:
    iPhone: Sound muffled or low from the speaker or when speaking into the mic
    http://support.apple.com/kb/TS1631
    Cheers,
    Jeremy

  • TS4002 Icloud Mail doet not work properly with PC since a few days!!!

    Icloud Mail doet not work properly with PC since a few days!!!

    If you can't solve your issue and no one in the community can help, contact support to speak with a tech support agent at (800) 631-3811.
    - Peter

Maybe you are looking for

  • RuntimeException in Message-Mapping transformatio error in txt to txt  fcc

    hi in my design part i executed my mapping program , it executed successfully my src is <?xml version="1.0" encoding="UTF-8"?> <ns0:mt_sarat_txttxt_sender xmlns:ns0="http://Sarat">    <Company>       <Header>          <Key1>H</Key1>          <RecordI

  • One domain in different mailhost

    Sorry for my english: it's very terrible! I have Sun Java Communication Suite with Sun Java(tm) System Messaging Server 6.3-0.15 (built Feb 9 2007) libimta.so 6.3-0.15 (built 18:37:56, Feb 9 2007) Linux public23.dmz.ritanet 2.6.9-55.ELsmp #1 SMP Fri

  • Monthly Spending Limit

    I received a message that I reached my monthly spending limit.  So, I am not able to use Skype my acount and we are only a third of the way through the month.  It was suggested that I sign in with a second ID, however, I discovered that the applicati

  • A simple but well coloured feed reader written in bash

    Hello everyone. I wrote these two functions for my .bashrc: #!/bin/bash if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi feed() { if [ ! -d $FEED_BOOK

  • Table for maximum number of jobs scheduled

    Hi experts, What is the table that contains the maximum number of jobs that can be scheduled in background? I will reward all the helpful answers. Thanks, Ajay Edited by: ajay singh on Apr 10, 2008 6:29 AM