TO_DATE with YYYY format mask behavior

I was selecting records from a table where a date in the table is prior to a given year:
SELECT * FROM the_table WHERE date_col <TO_DATE('2006','YYYY');
On January 31st, this worked fine.
On February 1st, I started seeing records from January 2006.
When I run the following in SQL*Plus, the result is 2/1/2006:
SELECT TO_DATE('2006','YYYY') FROM DUAL;
I have used this format before (but perhaps not in the exact situation) and I've never seen this issue before.
SQL*Plus is version 8.0.6.0.0. The result occurs on database versions 10.2.0.3.0 and 10.2.0.4.0.
I'm not understanding why the current date would have any effect on the SELECTed date.
Any insights would be appreciated.
Thanks!

Hi,
When you don't spedcify the month in TO_DATE, it defaults to the current month.
SELECT  SYSDATE
,       TO_DATE ('2006', 'YYYY')
FROM    dual;just produced
02-Feb-2009 01-Feb-2006You have to give the month:
TO_DATE ('200601', 'YYYYMM')Edited by: Frank Kulash on Feb 2, 2009 3:21 PM
Or use TRUNC (..., 'YYYY'), as Walter showed you.

Similar Messages

  • Problem with date format mask 'D'

    I am experiencing an extremely thorny problem with the date format mask ‘D’. I am trying to use it to check whether today is a Monday. The variable v_temp_day is set to sysdate. For the last 4 weeks the code has behaved erratically – giving a different result at 02:00 than at 10:30 even though it is only taking account of the date. In desperation I inserted a debug statement formatting the date in a variety of ways – with interesting results. Oracle is somehow managing to tell us that today is simultaneously Monday and Tuesday depending on which format mask you choose. Anyone got any thoughts or suggestions?
    PROC_ID TO_CHAR(STAMP_TIM
    EVENT_SQLERRM
    RRHKP010 17092007 02:00:00
    TO_NUMBER( TO_CHAR( v_temp_day, D ) ) = 2. TO_CHAR( v_temp_day, D ) = 2. TO_CHAR( v_temp_day, DY ) = MON. TO_CHAR( v_temp_day, DAY )
    = MONDAY . TO_CHAR( v_temp_day, Day DD-MON-YYYY HH24MISS ) = Monday 17-SEP-2007 020000. TO_CHAR( v_temp_day, D ) = 2.
    SQL> select to_char( sysdate, 'D' ) from dual ;
    T
    1

    My book says the trunc(d,'iw') will return "same day of the week as Jan 1st of that year"It's bad book.
    Please read about [url http://oraclesvca2.oracle.com/docs/cd/B10501_01/server.920/a96540/functions176a.htm#80159]TRUNC & 'IW' Format Model and [url http://oraclesvca2.oracle.com/docs/cd/B10501_01/server.920/a96529/ch3.htm#50331]Database Globalization Support Guide: First Calendar Week of the Year in the manual.

  • Problem With Date Format Mask

    Hi everyone,
    when i set the date format mask in any field..
    if i enter any wrong date format messages are coming in to loop
    is this is bug of format mask?
    how can i avoid this..
    thanks in advance
    anand mohan

    It should not take you into a loop. If the "validation" against the format mask fails, a message is displayed, and the focus is returned to the field which caused the problem. Do you maybe have some method or event associated with the field which could be causing the circular behavior?
    -- Brian

  • Apex mobile Date-Picker (date with time) format mask error

    Hi together.
    I'm playing  a little bit with Apex mobile.
    I want to save a date with hours and minutes in the database. So i have an date field (type: date with time).
    On my phone i can select an date value with time, but when i want to save the value, i get an format error, that the format 'YYYY-MM-DD"T"HH24:MI:SS' is wrong.
    I can't change the format mask in the element properties, because it is everytime going back to the old value "YYYY-MM-DD"T"HH24:MI:SS", when i save it.

    Not a 100% related, but personally and from a usability point-of-view I really dislike the built-in datetimepicker and so far every client who has seen it has agreed with it. It pops the date and time down to the bottom, it only selects when you hit close, it just doesn't look appealing as the normal datepicker does and you expect more. Personally I've also gone the route Jari described several times, and it's probably still the cleanest and least error-prone option. Validating dates can be quite a pain, but the datepicker built-in validation does that fine, so if you can circumvent validating a free-text time field that helps). I've used some jQuery timepicker plugins aswell, and they're ok, but still don't solve the validation (even though there is some javascript validation you still need serverside validation). All I'm trying to say is that using select lists for hour-minutes is not such a bad idea in my opinion.

  • Need help with date format mask

    Hi there, right now I'm trying to set a default date format mask constraint for one of the attributes for my table. I want to set the default mask constraint as MM/DD/YY but I don't know how to. it should be something like:
    CREATE TABLE work (WorkDate DATE CHECK (WorkDate = 'MM/DD/YY'))
    or something like that, but I don't think that's correct. Can anyone help me? Thanks in advance.

    What you want (and should have done) is to read the documentation, starting with the concepts:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#CNCPT413
    http://www.oracle.com/pls/db102/search?remark=quick_search&word=date&tab_id=&format=ranked
    A date is stored as, well, a date, format masks only come into play when you're selecting/retrieving a date or when you want to store a string as a date. Default date formats can be set through NLS_DATE_FORMAT at session and database level.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams122.htm#REFRN10119
    Documentation homes (from which you can do a simple quick search):
    http://www.oracle.com/pls/db102/homepage
    http://www.oracle.com/pls/db112/homepage
    Bottom line:
    Trying to set a default date format mask on a date datatype column makes no sense...

  • Outputted date with unusual format mask

    I am getting a flat file outputed from Fusion Financials SAAS, and one of the columns has this: 2013-11-14T15:10:36.000-06:00
    Clearly its a date. I am guessing its a datetime TIMESTAMP WITH TIME ZONE datatype. But, the Format Model is unfamiliar to me, particularly regarding the letter 'T'.
    Because its a flat file, this is coming to me as varchar2 data. I'd like to convert it to datetime.
    I got to this:
    select to_timestamp_tz('2013-11-14T15:10:36.000-06:00', 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') AT LOCAL
    from dual
    It fails because of the letter 'T',
    I know I could do this:
    select to_timestamp_tz(REPLACE('2013-11-14T15:10:36.000-06:00','T',' '), 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') AT LOCAL
    from dual
    And it works.
    But that is not the point. The point is to find the Format Model that Oracle is using here.
    Any thoughts on this?
    Thanks,
    Arie

    Arie, the timezone format in the file is based on ISO 8601: ISO 8601 - Wikipedia, the free encyclopedia
    This should work:
    SQL> select to_timestamp_tz('2013-11-14T15:10:36.000-06:00', 'YYYY-MM-DD"T"HH24:MI:SS.FF TZH:TZM') from dual;
    TO_TIMESTAMP_TZ('2013-11-14T15:10:36.000-06:00','YYYY-MM-DD"T"HH24:MI:SS.FF
    14-NOV-13 03.10.36.000000000 PM +06:00
    Hope this helps,
    Oliver
    Fusion Apps Developer Relations
    https://blogs.oracle.com/fadevrel

  • Date format mask in Enter-Query mode

    Hi,
    I'm developing a Form which is able to query the masterblock from a detail-item.
    The queryable detail-item is a date field and has a datatype: DATETIME. When a new record is entered the values in the date field are stored in the database like "18-10-2002 15:04:02"
    When the form is in enter_query mode the user must be able to enter 18-10-2002 (DD-MM-YYYY format mask, so without time mask). When execute the query with this date format the query is not able to find data.
    I used a Key-Execute-Query on the detailblock like this:
    SELECT 1.COLUMN
    , 2.COLUMN
    INTO :1.COLUMN
    , :2.COLUMN
    FROM TABLE.1
    , TABLE.2
    WHERE 1.COLUMN = 2.COLUMN
    AND TO_CHAR(1.COLUMN,'dd-mm-yyyy') = to_date(:avg.datum,'dd-mm-yyyy');
    Can anyone please help me?
    Regards,
    Ronny.

    Hi Ronny,
    I'm not sure to have got exactly your issue (especially why you have to use that select in master-detail query), but I suggest you to substitute
    ...AND TO_CHAR(1.COLUMN,'dd-mm-yyyy') = to_date(:avg.datum,'dd-mm-yyyy');
    with
    ...TRUNC(1.COLUMN) = TO_DATE(:avg.datum,'dd-mm-yyyy');
    To be fair, I would use it in the where clause, even if you set it dinamically.
    Let us know,
    Marco

  • Date format Mask in Source Value Expression

    Hi there ,
    I am in situation where I will have to have a Formate Mask in the "Source" for the Page ITEM.
    Last refresh date for tables:  &P76_DATA_LOAD. I have the source as refered above. I want that &P76_DATA_LOAD. to have mm/dd/yyyy format mask . How do I do it ? ANy help will be highly appreciated.

    Hi,
    only a string that holds a data will have format masks.
    The way your date column shows up in your database is set up using nls_date_format parameter,
    If you want a string you can just use TO_CHAR(P76_DATA_LOAD,'mm/dd/yyyy')
    If you want your date column to be displayed as above then change the nls_date_format parameter.
    G.

  • Format Mask in Session state

    In a Summary Region (Page 6) I have changed one field to text, edited the field with no format mask. In the entry form on the pervious page, the column properties are Database Column, and Always replace value in Session State with the Money format Mask.(Page 5).
    10313     5     P5_LPP     Text     $66.67 LPP
    10313     6     P6_ENGAGER_LPP     Text Field     $66.67     I
    Question is that the field in field 6 displays the value $66.67. Why not 66.67?
    On Page 6 a user can press the Update_lpp button and Invalid Number Error Page pops up?
    Is there a way to hold in the session state the values only while formatting on the screen is $'
    Thanks

    Thanks. I did an "on submit and before computation" process that did a SQL replace on the page item. The DML process then successfully inserted the value into the database.
    Alex.

  • How to ignore/remove number format mask ?

    Hi
    I have to import some numbers from the excel sheet, and that number has been saved along with the format mask like (9,999.99) (2,000.00,1,500,00,......)
    but that field in my table is a number filed and i have to equal that number with the number that exist in my table
    i have write that relation like
    mytable.filed1=to_number('excel_filed',9,999.000)
    but I does not work
    So what the solution for that
    Thank you

    Double post. See How to remove a number format mask ?

  • 'MB' Format Mask

    Good Morning Everyone,
    I have a report that calculates the memory used in a certain database. There are only 2 columns in this report "database" and "mem_used". At the moment the mem_used column is only numbers, but what i would like is to have a format mask of 'MB' to be placed at the end of the numbers, but i am a bit stuck.
    Please can someone help me?
    Thanks in Advance,
    -N.S.N.O.

    Hey,
    Thanks for your responce, i have tried that way of doing it. However, when i try that i lose the ability to order by that column.
    I had a similar problem with using dates, if i used to_char i lost the ability to order by but with a format mask i could still order by
    -N.S.N.O.

  • Formating Numbers Using Word Format Mask

    Hello!
    Usually i use this format command to format my elements inside of each layout ( '<?format-number:Total_Price_w_o_Tax_ID12;'999G999D99'?>' ) but in this specific case i have one form field that contains the sum of a xml field ( ' <?sum(current-group()/Taxable_Ammount_ID9)?>' ) and i cant use format-number command to the format so i tryied with word format mask #.00##0,00. My problem is when i have for exemple 75 with 00 decimals it appears '75' and i want '75.00' . if i have 75.29 i dont have problems . Someone know how i can get '75.00' instead of '75' ?
    Thanks in advance

    Instead of using format-number, could you do this?
    <?xdoxslt:pat_format_number(sum(current-group()/Taxable_Ammount_ID9), '#.00', $_XDOLOCALE)?>

  • Using a datepicker with format mask MM/YYYY gives error on submit

    I'm trying to use a datepicker with the format MM/YYYY.
    The item is linked to a database column of type DATE.
    The items displays correctly (month and year), but when submitting the page, I get an "ORA-01843: not a valid month" error from the built-in DML process.
    Shouldn't Apex apply the same date format mask to the item value when trying to save it to the database?
    - Morten
    http://ora-00001.blogspot.com

    Hi Mike,
    I can/need to do that for my own PL/SQL processes, but the problem is with the Built-In DML Process....
    - Morten
    http://ora-00001.blogspot.com

  • Problem with  date format "dd-MM-yyyy"

    hi all,
    i am using jdev 10.1.3.2
    My application ADF Swing app.
    in my database i have a table employee which contains "birthday".
    my problem is that i must use date format"dd-MM-yyyy".
    i added this format into "formatinfo.xml" file.
    than i choose it in my EO.
    i create a form which contains employees.
    for example i have an employee with a birthday=25-10-1970
    in my text field if user puts "1970-10-25"'which is not the best format) he will have a correct result "25-10-1970"
    but if user puts "25-10-1970" he will have as result "21-02-0031" which is not the real value.
    please help me.
    thanks.
    PS: i did some research before posting but i didn't find yet

    Rouz,
    Did you try what i said before?
    * Open you EntityObject
    * Expand the attribute tree
    * Choose your DOB attribute
    * Choose the Control hints pane on the right
    * Choose Formater: Simple date format
    * Choose Format mask dd-MM-yyyy
    Run your application and try it.
    This is how i change the format and it works perfectly.
    I uses the correct format to show the date and it enables me to edit the date using the format mask dd-MM-yyyy
    Edit: I just tried it myself. I can only reproduce it by removing my mask. Ergo, the application expects the default american format yyyy-MM-dd. By entering a date in the format dd-MM-yyyy the framework will convert it to yyyy-MM-dd and you'll end up with 0031-02-21.
    CONCLUSION follow the steps i discribed above to set your mask and you'll be fine.
    Message was edited by:
    Smolders Johan

  • Date Format Mask with text only...

    Hi!
    I have a problem with my date text item: the format mask is set to YYYY-MM-DD HH24:MI:SS and it work perfectly if the user enter only numeric character, it will validate the date correctly. But if the user enter a value only alpha (something like 'uuuuyyyy') instead of validate with the mask format it will fire an error trigger ORA-06502.
    I want to know if it's possible to check if the user has enter only alpha to bypass this problem.
    Also, how can a check that a date field is null. I Try with : IF :BLOCK_NAME.DATE_ITEM IS NULL THEN ...
    AND ALSO with IF TO_CHAR(:BLOCK_NAME.DATE_ITEM) IS NULL THEN... and nothings seems to work.
    Thanx in advance.

    AFAIK, the only way to do this is to have two items. One is a hidden database item, type DATETIME, to hold the date value.
    The other is a non-database character item, visible to the user. You populate it at POST-QUERY from the database field, and use an ON-VALIDATE-ITEM to copy any value entered/changed by the user over to the hidden field. If you're smart, you'll write a library procedure to do the on-validate stuff, passing it the names of the two items.
    In that procedure, you can attempt to convert the entered text into a valid date using whatever date format(s) you like, only raising an error if you can't do it at all.

Maybe you are looking for