Sort data in date format DD/MM/RRRR

Hello

I have to sort our data between two dates ex 01 01, 2016 to the 31/01/2016 for the list of transactions.

Will I convert in JAN-16 format so that I can sort by where period_name like ' JAN-16'?

If so how do I convert a date format of 01/01/2016 JAN-16?

Thank you

Hello

Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum: Re: 2. How can I ask a question on the forums?

As Chris and Tubby has said, all DATEs are stored in the same internal format, which has nothing to do with the format you use to view or format you use in conversion as TO_DATE functions.

Oracle provides many functions and other features for the manipulation of DATEs, you seldom need to convert them to another format.  For example, we wanted to get a list of employees of the scott.emp sorted by month and by ename; in other words, December 1980 would come before April, 1981, as from habit, but the day of the month, hours minutes and seconds would all be ignored in sorting.  We can use the TRUNC function to do this:

SELECT TO_CHAR (hiredate, 'Mon-YYYY') AS hiremonth

ename

hiredate

FROM scott.emp

ORDER BY TRUNC (hiredate, 'MONTH')

ename

;

Output:

HIREMONTH ENAME HIREDATE

---------- ---------- -----------

DEC-1980 SMITH December 17, 1980

Feb-1981 ALLEN 20 February 1981

Feb-1981 WARD 22 February 1981

Apr-1981 JONES April 2, 1981

May-1981 BLAKE may 1, 1981

Jun-1981 CLARK June 9, 1981

MARTIN 1981-Sep 28-Sep-1981

Sep-1981 TURNER 08-Sep-1981

Nov-1981 KING November 17, 1981

DEC-1981 FORD December 3, 1981

DEC-1981 JAMES December 3, 1981

Jan-1982 MILLER January 23, 1982

Apr-1987 SCOTT April 19, 1987

May-1987 ADAMS 23 May 1987

Notice how MARTIN comes before TURNER in the output (I marked these Redlines), even if MARTIN hiredate is 20 days later than TURNER.  This is because only the year and month are considered in the sorting.  Any DATE in the same month will get the same sort value.

Tags: Database

Similar Questions

  • ADF: Affecting date format DD-MON-RRRR

    Hello world

    I use Jdev 11 G.

    I created a VO with the query: select * from employees.
    VO has 24 columns. The column is column hiredate that is currently displayed in the: 25/06/2008, but
    My requirement is to change the format of 25 June 2012.

    How can I achieve this?
    All responses will be very grateful.

    Thank you...

    Go to the view object. Choose the attribute... under the guidance of the user interface... Foramt type, and then select date Simple... and you can define your own format.

    I hope this helps.
    Rakesh

  • Error: Please enter the date value in the correct format DD-MON-RRRR

    Hi all
    First of all, I am 100% not learning financial oracle no technical information. I'm trying to run a report: - the calendar does not appear in order for me to choose the date - not to mention that when I enter the date IE 10/09/2010 or on 09/10/2010 the system gives me this error "" error: Please enter the date value in the correct format DD-MON-RRRR ".
    Please help me to solve this.

    Thank you

    Please enter date in format 12 October 2010.

    Kind regards
    http://www.oraerp.com

  • Convert the Period_Name in GL_JE_Lines table to a date format and then come back year

    I'm working on a data model BI Publisher and I try to convert the Period_Name in GL_JE_Lines table to a date format and then return of the year.

    The sql below works in 11i, but I can't make it work in Fusion.

    to_char (to_date (l. )) period_name , ' MON-RR ' ),'YYYY')

    Any ideas?

    Hi Jennifer,.

    To_char (sysdate, 'DDMONYYYY') in BI Publisher does not return a correct results due NLS_DATE_FORMAT/DATE_LANGUAGE settings.

    According to the standards of the I18N, NLS_DATE_LANGUAGE in the database is still hardcoded to NUMERIC_DATE_LANGUAGE. NUMERIC_DATE_LANGUAGE 'MY' in a date format mask is an integer, so you see the correct value.

    You're not supposed to publish direct SQL with fixΘe format masks (unless it's some sort of canonical format used in internal processing, including the end-user will not be), you should return language digital date to the mid range and then make the formatting of y.

    Workaround

    Try adjusting the NLS_LANGUAGE in SQL data model to override formatting from of the

    Data base and values of the Session, for ex: select to_char (sysdate, 'MON-DD-YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') of double;

    I got this Oracle support after lifting a SR.

    Thank you

    Rahul.

  • Date format and XML (XmlType)

    Hi all

    I'm trying to generate XML in PL/SQL.
    select xmlelement("Date", sysdate).getClobVal() from dual;
    
    XMLELEMENT("DATE",SYSDATE).GETCLOBVAL()
    -------------------------------------------
    <Date>2012-07-13</Date>
    This is the date format, I was expecting (date format XML standard).

    And the Documentation of Oracle described:
    "The XML schema standard specifies that the dates and timestamps in the XML are in standard formats. Generation of XML in Oracle XML DB functions produce dates XML and timestamps in accordance with this standard. »


    When I want to create an XML from a query, I tried this
    DECLARE
    
       l_refcursor SYS_REFCURSOR;
       l_xmltype xmltype;
       l_ctx dbms_xmlgen.ctxHandle;
         
    BEGIN
    
       OPEN l_refcursor FOR select sysdate "Date" from dual;
    
       l_ctx := dbms_xmlgen.newContext (l_refcursor);
       dbms_xmlgen.setRowTag (l_ctx, null);
       dbms_xmlgen.setRowSetTag (l_ctx, null);
       l_xmltype := dbms_xmlgen.getXMLType (l_ctx);
       dbms_xmlgen.closeContext (l_ctx);
       
       dbms_output.put_line(l_xmltype.getClobVal());
    END;
    /
    
    <Date>13-JUL-12</Date>
    I was also expecting the date format XML standard, but I get the nls_date_format.

    Of course I can use to_char and specify the correct date format, or do an alter session (alter session set nls_date_format = 'RRRR-MM-DD';), but I wonder why XMLElement uses the standard and not the dbms_xmlgen.
    Or y at - it another way to use the default XML standard?

    Gert

    Or y at - it another way to use the default XML standard?

    You can return to the dbms_xmlquery based on java instead:

    SQL> alter session set nls_date_format='rrrrhh24'  ---just to show the result is independent from nls_format
    /
    Session altered.
    
    SQL> declare
      l_xmltype   xmltype;
      l_ctx       dbms_xmlquery.ctxhandle;
    begin
      l_ctx := dbms_xmlquery.newcontext ('select sysdate "Date" from dual');
      dbms_xmlquery.setrowtag (l_ctx, null);
      dbms_xmlquery.setrowsettag (l_ctx, null);
      l_xmltype := xmltype (dbms_xmlquery.getxml (l_ctx));
      dbms_xmlquery.closecontext (l_ctx);
    
      dbms_output.put_line (l_xmltype.getclobval ());
    end;
    /
    
    2012-07-13 22:45:25
    PL/SQL procedure successfully completed.
    
  • convert date format dd.mm.yyyy jj.mm.AA

    Hi all

    My need is to convert date format dd.mm.yyyy jj.mm.AA. All years are 1999 or less. My first assumption is to use the combination of substr with concatination of '19', but maybe someone can suggest another decision.
    select '18.03.97' as dt from dual

    You can do this:

    SQL> select to_char(to_date('18.03.97','dd.mm.rrrr'),'dd.mm.rrrr') Result from dual;
    
    RESULT
    ----------
    18.03.1997
    
  • date format not correctly displayed

    Hi all
    I am writing a procedure to download an excel file in a table. for this, we use a csv format.
    I have a DATE column in my spreadsheet. prior to the main question. I want you to know is that this spreadsheet is generated by another application (so there is no possibility to manually change the column format in excel).

    the format in which the date is stored is lun-JJ-AA. so, if the date is January 1, 2000, it is displayed as January 1 00.

    When convert us this spreadsheet to CSV data are not complete in the csv file. This is the January 1 00.

    now the problem is that u cannot use a function to_date for the above data. It gives an error like invalid date.

    can you let me know how can I handle this in the query and the query only?

    Thank you
    Belin
    select to_date('1-jan-00','dd-mon-YYYY') from dual
    
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    
    select to_date('1-jan-00','DD-MON-RRRR') from dual
    
    1/1/2000
    
    for more details
    Difference between YYYY n RRRR date format
    
  • Issue Date format as a VARCHAR

    Using Oracle 10 g:
    I have a varchar field that keeps a date like:

    2010-08-28 14:40:21

    I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

    To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

    I get an error message:
    ORA-01722: invalid number
    01722 00000 - "invalid number."

    Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

    Hello

    user9179751 wrote:
    Using Oracle 10 g:
    I have a varchar field that keeps a date like:

    2010-08-28 14:40:21

    I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

    To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

    I get an error message:
    ORA-01722: invalid number
    01722 00000 - "invalid number."

    Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

    Is the VARCHAR2 column end_date?
    To_char, as its name suggests, converts a DATE to a string of record CHAR. If you already have a string of characters, so there's no need of TO_CHAR.
    You can call TO_DATE, such as

    WHERE   TO_DATE ( end_date
                    , 'YYYY-MM-DD HH24:MI:SS'
                    )  > SYSDATE
    

    but it is more effective and less prone to say

    WHERE   end_date > TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
    

    Why is it more effective? The optimizer considers SYSDATE be a constant, even if the query takes a long time. Therefore, it only will convert SYSDATE in a string once, even if you have 1 million rows in the table. If you did the first way, you must call TO_DATE a million times, once for each line. In addition, your column, end_date, being alone on one side of the > operator, the optimizer can use an index on that column.
    Why is it less error-prone? If you still have a line where End_date is incorrect, you will get an error if you call TO_DATE. Not try to convert end_date, you won't make mistakes.

    This works because the format for End_date is suitable for sorting. If the format was, say, 'DD-Mon-YYYY', you would have to be converted to a DATE.

    It would be better if End_date a DATE column. It is never a good idea to use a VARCHAR2 column to store points in time.

  • Valid date format

    Version: 10 g Release2

    For SQLs with columns date, I always get an error like
    select TO_DATE('12-05-10', 'DD-MON-RR') from dual;
    select TO_DATE('12-05-10', 'DD-MON-RR') from dual
                   *
    ERROR at line 1:
    ORA-05843: not a valid month
    Where can I find the valid date formats in Oracle?



    What is the difference between RRRR and YYYY formats? Documentation
    http://download-West.Oracle.com/docs/CD/A87860_01/doc/server.817/a85397/sql_elem.htm#36369
    They both seemed same.

    ScottsTiger wrote:
    Version: 10 g Release2

    For SQLs with columns date, I always get an error like

    select TO_DATE('12-05-10', 'DD-MON-RR') from dual;
    select TO_DATE('12-05-10', 'DD-MON-RR') from dual
    *
    ERROR at line 1:
    *ORA-05843: not a valid month*
    

    Where can I find the valid date formats in Oracle?

    05 isn't one month valid for the format mask the LUN. You must use mm. LUN would be MAY or MAY according to the NLS language.

    select TO_DATE('12-05-10', 'DD-MM-RR') from dual;
    

    With regard to the RR. In this example, that would make difference o. -However, if your channel is 12/05/99 then see for yourself:

    SQL> alter session set nls_date_format = 'DD-MON-YYYY';
    
    Session altered.
    
    SQL> select sysdate from dual;
    
    SYSDATE
    -----------
    21-JUN-2010
    
    SQL> select TO_DATE('12-05-99','DD-MM-RR') from dual;
    
    TO_DATE('12
    -----------
    12-MAY-1999
    
    SQL> select TO_DATE('12-05-99','DD-MM-YY') from dual;
    
    TO_DATE('12
    -----------
    12-MAY-2099
    
    SQL> 
    

    Published by: Sven w. June 21, 2010 19:20

  • How to advocate for regional change of short date format

    This is something relatively trivial but annoying all the same, but I don't know where to go to advocate for change.

    Have just updated for Sierra and one of the first things I notice is the addition of a point at the end of the month in short date format, i.e. 'September 19, 2016'.

    "In Australia, as in the United Kingdom, the standard must not use this period - it should be just'19 Sep 2016", and in the past, that's how it appeared in OSX for the Australia. Don't know why the change.

    This abbreviation is not replaceable by the user, so where can I go to provide appropriate feedback and I hope to have this problem on the track?

    A solution is to make my default language and region of the United Kingdom, but do not know if there is a price to pay for it.

    You can provide feedback to Apple asking them to change it:

    www.Apple.com/Feedback

  • How do I change the date format in the section of the United States to the United Kingdom

    As in the question.

    Hello

    I had a glance in this and have found that Thunderbird uses the date format of your computer system. If you change it, it should be reflected in Thunderbird.

    I hope this helps, but if not, please come back here and we can look at another solution for you.

  • How can I configure the cell data format

    How can I configure data format of cell numbers: for example, I want to capture 123456.78 and need to be 12A3456.78?

    I tried to put #A # #. # format option, but it didn't work a few time and it became A123456.78.

    I also tried on excel and it worked very well, but I like the numbers better. is there a solution to this problem?

    Thank you

    HEY Chi - Lun,

    I don't think that this is possible as many number format. You should be able to insert A in a text string using a formula, but this would happen in a second cell, not that the number has been entered.

    "Assuming all the"numbers require the same inserted letter after the second number, this should do the work."number" entered in column A; the formula in column B. In the table below, your value as an example is A6.

    = Left (A, 2) & "A" & RIGHT (A, LEN (A) - 2)

    Kind regards

    Barry

  • Date format of messages is absolutely ugly

    Hi all.

    I'm really frustrated format of date/time of Messages on my iPhone6 (and also on my OS - X).

    What the main reason for the use of the words 'Today', 'Yesterday', 'Saturday' and other?

    Who need this lyrical sh * t? All my friends is also frustrated by this function, because if you need a specific date for the quote or shipping screen, you will need to do a lot of unnecessary travel.

    I mean - if you want to find something and need to translate "what the date was Saturday?", you need to go to calendar and look here, what date was Saturday.

    Apple !

    Please, I beg you! Make this switchable feature!

    This date format looks like completely unnecessary and useless decoration.

    Simply return the precise date.

    p.s. this message angry wrote after a misunderstanding with screenshots attached in the e-mail Messages.


    iOS version: 9.3.3

    The OS - X version: 10.11.6

    Not something anyone here can do for you. You can offer your comments Apple here.

  • How canI change the date format of dd/mm/yyyy to dd/mm/yyyy in filed?

    I just got and try things my new Alcatel fire E with FirefoxOS (just updated) 2.0.0.0.

    It is usual in most operating systems to be able to customize the date and time (among others). After a few hours of unsuccessful fiddling with the phone and checking the various forums, I came to the conclusion that it is currently not possible on my phone with this version of FirefoxOS. Or did I just miss something?

    Achim

    Hi achim_59,

    I understand that you want to set the date format to display the jj/mm/aaaa on your Firefox OS device.

    This feature has been implemented in Firefox OS v2.1. Unfortunately, this feature is not available in v2.0:

    For other questions about the updates and implementation of your specific device features, please contact your device manufacturer, Alcatel.

    -Ralph

  • How can I change the date format in Thunderbird for the list of received messages?

    Through 19/02/2015 12:28, I received my email with this format. Since that time, all the date Watch column is the time, the date does not show. How to get back to the default time and date format?

    The default is to show all the time on messages from today, with the date and time on all the other messages.

    http://KB.mozillazine.org/Date_display_format

Maybe you are looking for

  • The film shared iMovie displays noise and horizontal lines where I have added a few pictures

    I've added a few photos at the end of my film (about 7 min long, 4 k, but to 1020), but at the beginning a few black and white lines appear instead of the photo and this also happens with another photo.

  • Firefox will not load some sites Web but IE

    After the upgrade to 29 FF, I can't access the addons and several other pages. Going to addons.mozilla.org or clicking the addons button gives me a bulleted links list. Try to download an add-on just says "download error". I can go to addons.mozilla.

  • a public access remote vpn from an inside interface asa 5505

    I'm trying to see if it is possible to accomplish what I am trying. I have an ASA 5505 with the following configuration. 1. There is an external connection, connected to the ISP. Let's say that it is 10.1.1.1/24 for ease. There is a remote VPN config

  • Windows 8 keeps minimisinng programs full screen

    Please can someone help me fix this problem dishes I'll play a game and randomly, it reduces to a minimum and take me back to the desktop. This is a new copy of windows must be added. I don't have any other software other than Microsoft Security esse

  • How to apply the race to several forms on the CC animate?

    I have a layer that has many forms without any style.Now, I want to add them both the same race / line.How do I do that? No matter what I tried, nothing works. The only option I see is the application to each of them by using the ink bottle tool, whi