Max(to_char(date,'DD-MM-YYYY')) ?

Hi All,
SQL> desc hday;
Name Null? Type
H_DATE NOT NULL DATE
SQL> select max(h_date) from hday;
MAX(H_DATE
03-JAN-11
SQL> select max(to_char(h_date,'DD-MM-YY')) from hday;
MAX(TO_C
31-12-99
SQL> select max(to_char(h_date,'DD-MON-YY')) from hday;
MAX(TO_CH
31-MAY-99
My question is why am i getting different dates when i use different date formats in MAX function ?
any ideas ?
greddy

Always compare dates in date format. don't use to_char and then a function on top of it. Use the function on the date type. Also, check this out:
SQL> create table hday(h_date date);
Table created.
SQL> insert into hday values('03-JAN-11');
1 row created.
SQL> insert into hday values('31-MAY-99');
1 row created.
SQL> insert into hday values('31-DEC-99');
1 row created.
SQL> SELECT * FROM HDAY;
H_DATE
03-JAN-11
31-MAY-99
31-DEC-99
SQL>  SELECT TO_CHAR(H_DATE, 'DD-MON-YYYY')
  2   FROM HDAY;
TO_CHAR(H_D
03-JAN-2011
31-MAY-1999
31-DEC-1999
SQL> SELECT TO_CHAR(H_DATE, 'DD-MON-RRRR')
  2  FROM HDAY;
TO_CHAR(H_D
03-JAN-2011
31-MAY-1999
31-DEC-1999
SQL> select max(h_date)
  2  from hday;
MAX(H_DAT
03-JAN-11Now this makes a little more sense! In sumary, after y2k oracle recognizes any year before 1950 to be of the 2000's and any year after 1950 to be of the 1900's. For example, 00 is 2000 and not 1900. Also, 51 is 1951 and not 2051. To give you the exact terminology and logic behind I would have to look in the documentation. To avoid this problem, user four digit year when working with dates.
SQL> insert into hday values('03-JAN-1911');
1 row created.
SQL> SELECT TO_CHAR(H_DATE, 'DD-MON-YYYY')
  2  FROM HDAY;
TO_CHAR(H_D
03-JAN-2011
31-MAY-1999
31-DEC-1999
03-JAN-1911
SQL> select to_char(min(h_date), 'dd-mon-yyyy') dt
  2  from hday
  3  union
  4  select to_char(max(h_date), 'dd-mon-yyyy') dt
  5  from hday;
DT
03-jan-1911
03-jan-2011

Similar Messages

  • Find out the MIN & MAX of DATE QUARTERWISE

    Hi All ,
    I need to find out the MIN & MAX of DATE for QUARTEWISE by using SQL Only . How we can do it ? if anybody knows Please revert me .
    Thanx in Advance
    Bye

    SQL> select deptno,
    2  to_char(trunc(hiredate,'q'),'YYYY"Q"Q'),
    3  to_char(min(hiredate),'DD.MM') MIN,
    4  to_char(max(hiredate),'DD.MM') MAX
    5  from emp
    6  group by deptno, trunc(hiredate,'q');
        DEPTNO TO_CHA MIN   MAX
            10 1981Q2 09.06 09.06
            10 1981Q4 17.11 17.11
            10 1982Q1 23.01 23.01
            20 1980Q4 17.12 17.12
            20 1981Q2 02.04 02.04
            20 1981Q4 03.12 03.12
            20 1987Q2 19.04 23.05
            30 1981Q1 20.02 22.02
            30 1981Q2 01.05 01.05
            30 1981Q3 08.09 28.09
            30 1981Q4 03.12 03.12

  • TO_DATE(TO_CHAR(sysdate, 'MM/DD/YYYY'), 'MM/DD/YYYY')

    Hi all,
    I am working with a Oracle 9i R2 database
    SQL>select TO_CHAR(sysdate, 'MM/DD/YYYY') CHRDATE from dual;
    CHRDATE
    11/14/2005
    SQL>select TO_DATE(TO_CHAR(sysdate, 'MM/DD/YYYY'), 'MM/DD/YYYY') mydate from dual;
    MYDATE
    14-NOV-05
    I want to retain the 4 digit year. Please suggest what I am doing incorrect.
    Thanks

    Your select statement,SQL>select TO_DATE(TO_CHAR(sysdate,...is equivalent toselect sysdate...And whenever you select a date, SQL Plus has to convert it to a character format before it can display it on the SQL Plus output screen.
    The four-digit year IS being retained internally ...until you display it on the screen. If you just set the default date format for displaying dates to include the four-digit year, you will see the full year:
    SQL> select SYSDATE mydate from dual;
    MYDATE
    14-NOV-05
    SQL> alter session set nls_date_format = 'MM/DD/YYYY';
    SQL> select SYSDATE mydate from dual;
    MYDATE
    11/14/2005
    SQL> select TO_DATE(TO_CHAR(sysdate, 'MM/DD/YYYY'), 'MM/DD/YYYY') mydate from dual;
    MYDATE
    11/14/2005

  • To_char(adate,'dd.mm.yyyy')   returns different results  from  two oracle clients !!! Is it  possible?

    Dear all;
    We have only one Database server with some IIS's   as web servers on front . Each web server has own oracle client software in order connect to central database..
    The same following query used in C#  code  returns different results on each IIS server.(3 row, or  not data found )
    why?
    select     *    from    aTable    where        to_char( adate ,  'dd.mm.yyyy' )  =   :search_date
    regards
    Siya

    1006237 wrote:
    If adate is of DATE datatype, it will most likely has the time component. Therefore your SQL below is unlikely to return any data.
    select * from aTable where adate = to_date(:search_date, 'dd.mm.yyyy')
    Perhaps.....
    select * from aTable where TRUNC(adate) = to_date(:search_date, 'dd.mm.yyyy')
    Hi,
    not having any sample data from you I could not understand that you wanted to select the range 00:00:00 - 23:59:59 on search_date.
    Your method might not be efficient if you have an index on adate.
    Maybe something like this will be more efficient
    select * from aTable
    where adate >= to_date(:search_date, 'dd.mm.yyyy')
      and adate <  to_date(:search_date, 'dd.mm.yyyy') + 1;
    If you search_date is 30-Aug-2013 it will get records where adate >= 30-Aug-2013 00:00:00 and adate < 31-Aug-2013 00:00:00, so any time of date 30-Aug-2013.
    Try like this and let us know if you still have 2 different results.
    Regards.
    Alberto

  • To_date(to_char(sysdate,'dd/mm/yyyy hh24:mm'),'dd/mm/yyyy hh24:mm')

    Hi
    I am using this conversion to_date(to_char(sysdate,'dd/mm/yyyy hh24:mm'),'dd/mm/yyyy hh24:mm')
    but it says format string appears twice
    Could some one please help me with this?

    user11365275 wrote:
    I have a requirement for taking hh:mi from a date ..ie i need to compare two dates till hrs and mins level but not secs..so i was trying to take the date till hrs,mins and then convert to dates and compare them...Exactly this is my requirement
    to_date(TO_CHAR(LOAD_DATE,'DD/MM/YYYY HH24:Mi'),'DD/MM/YYYY HH24:Mi')
    <(SELECT to_date(TO_CHAR(CURRLOADTIME,'DD/MM/YYYY HH24:Mi'),'DD/MM/YYYY HH24:Mi')
    FROM Table1 WHERE
    JOBNAME='DEFAULT_EVENT_LOG');
    PLease can you suggest anything better than this comparison or let me know if this works correct nowYou are using a TO_CHAR to format a date field in a string. Then use a TO_DATE to change it back to a date. This "double" formatting is a deep misunderstanding about what is a date field.
    If you want to compare dates and get rid of the seconds, use truncate, for instance :
    SQL> select trunc(sysdate,'mi'),sysdate from dual;
    TRUNC(SYSDATE,'MI') SYSDATE
    02/02/2010 09:18:00 02/02/2010 09:18:55Your WHERE clause will become :
    ...trunc(LOAD_DATE,'mi')<(SELECT trunc(CURRLOADTIME,'mi')...Nicolas.

  • TO_CHAR(hire_date,'fmDD MONTH YYYY') TO_CHAR(hire_date,'DD MONTH YYYY')

    Given following 2 querys on sample table employees.
    Both return diffrent row. But can't identify on what gorud it is working. as both the column look exactly same in list.
    TO_CHAR(hire_date,'fmDD MONTH YYYY') <> TO_CHAR(hire_date,'DD MONTH YYYY')
    (1st Query)
    SELECT employee_id, hire_date,TO_CHAR(hire_date,'fmDD MONTH YYYY') Month_Hireed,TO_CHAR(hire_date,'DD MONTH YYYY')
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH YYYY') <> TO_CHAR(hire_date,'DD MONTH YYYY');
    (2ndt Query)
    SELECT employee_id, hire_date,TO_CHAR(hire_date,'fmDD MONTH YYYY') Month_Hireed,TO_CHAR(hire_date,'DD MONTH YYYY')
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH YYYY') = TO_CHAR(hire_date,'DD MONTH YYYY');
    Chk result of query 1).
    One can easily figure out difference between 5 & 05. But what is difference between 15 & 15 ?
    Seems apart from September Month everything fall under != NOT EQUAL to sings.
    1)
    SQL*Plus ReportSELECT hire_date AS "DATE", TO_CHAR(hire_date,'fmDD MONTH RRRR')
    AS "A", TO_CHAR(hire_date,'DD MONTH RRRR') AS "B"
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH RRRR') != TO_CHAR(hire_date,'DD MONTH
    RRRR');
    DATE------------------------------ A--------------------------------------- B
    17-JUN-87...........17 JUNE 1987...................17 JUNE 1987
    13-JAN-93...........13 JANUARY 1993............13 JANUARY 1993
    03-JAN-90.............3 JANUARY 1990............03 JANUARY 1990
    21-MAY-91......... 21 MAY 1991....................21 MAY 1991
    25-JUN-97.......... 25 JUNE 1997...................25 JUNE 1997
    05-FEB-98........... 5 FEBRUARY 1998......... 05 FEBRUARY 1998
    07-FEB-99........... 7 FEBRUARY 1999......... 07 FEBRUARY 1999
    2)
    SQL*Plus ReportSELECT hire_date AS "DATE", TO_CHAR(hire_date,'fmDD MONTH RRRR')
    AS "A", TO_CHAR(hire_date,'DD MONTH RRRR') AS "B"
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH RRRR') = TO_CHAR(hire_date,'DD MONTH RRRR');
    DATE------------------------------ A----------------------------------------------- B
    21-SEP-89...........21 SEPTEMBER 1989...........21 SEPTEMBER 1989
    28-SEP-97...........28 SEPTEMBER 1997...........28 SEPTEMBER 1997
    30-SEP-97...........30 SEPTEMBER 1997...........30 SEPTEMBER 1997
    28-SEP-98...........28 SEPTEMBER 1998...........28 SEPTEMBER 1998
    17-SEP-87...........17 SEPTEMBER 1987...........17 SEPTEMBER 1987
    [….. are add to increase readability as cant post in html format here]
    Message was edited by:
    user554589

    Chk result of query 1).
    One can easily figure out difference between 5 & 05. But what is difference between 15 & 15 ?
    Seems apart from September Month everything fall under != NOT EQUAL to sings.
    1)
    SQL*Plus ReportSELECT hire_date AS "DATE", TO_CHAR(hire_date,'fmDD MONTH RRRR')
    AS "A", TO_CHAR(hire_date,'DD MONTH RRRR') AS "B"
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH RRRR') != TO_CHAR(hire_date,'DD MONTH
    RRRR');
    DATE------------------------------ A--------------------------------------- B
    17-JUN-87...........17 JUNE 1987...................17 JUNE 1987
    13-JAN-93...........13 JANUARY 1993............13 JANUARY 1993
    03-JAN-90.............3 JANUARY 1990............03 JANUARY 1990
    21-MAY-91......... 21 MAY 1991....................21 MAY 1991
    25-JUN-97.......... 25 JUNE 1997...................25 JUNE 1997
    05-FEB-98........... 5 FEBRUARY 1998......... 05 FEBRUARY 1998
    07-FEB-99........... 7 FEBRUARY 1999......... 07 FEBRUARY 1999
    2)
    SQL*Plus ReportSELECT hire_date AS "DATE", TO_CHAR(hire_date,'fmDD MONTH RRRR')
    AS "A", TO_CHAR(hire_date,'DD MONTH RRRR') AS "B"
    FROM employees
    WHERE TO_CHAR(hire_date,'fmDD MONTH RRRR') = TO_CHAR(hire_date,'DD MONTH RRRR');
    DATE------------------------------ A----------------------------------------------- B
    21-SEP-89...........21 SEPTEMBER 1989...........21 SEPTEMBER 1989
    28-SEP-97...........28 SEPTEMBER 1997...........28 SEPTEMBER 1997
    30-SEP-97...........30 SEPTEMBER 1997...........30 SEPTEMBER 1997
    28-SEP-98...........28 SEPTEMBER 1998...........28 SEPTEMBER 1998
    17-SEP-87...........17 SEPTEMBER 1987...........17 SEPTEMBER 1987
    [….. are add to increase readability as cant post in html format here]

  • In IOS 6 my date format was YYYY-MM-DD. When I switched to IOS 7, it changed to MM-DD-YYYY. How do you change it?

    In IOS 6 my date format was YYYY-MM-DD, which is ISO 8601 standard used in Canada.  When I switched to IOS 7, it changed to MM-DD-YYYY format which is very confusing as all my cameras etc use YYYY-MM-DD.  How do you change it, like one can in OSX?

    It appears previous versions of IOS would pick up your preferred date format from your OSX Mac. You can modify that to whatever you like.
    Now if you select Canadian or American in IOS 7 you get only MM-DD-YYYY.  This is wrong for Canada as the preferred date format here is YYYY-MM-DD, just check your birth or expiry dates on your Ontario Drivers License or OHIP Health Card.  Or the date field at the bottom left of any Government of Canada website.
    The trouble with using other Country codes is you tend to get their currency codes like € or £ and the terms like yesterday and today in their language.

  • How to convert Date format from yyyy mm dd   to   dd mmm yyyy in ADF

    Hi,
    I have Date Format in Data Base as yyyy mm dd, but in the UI I want to display the format as dd mmm yyyy, which code I have to write to get the required format in JDev 11.1.2.3

    Hi,
    Use converter : &amp;lt;af:convertDateTime&amp;gt;
    See also : convertDateTime Demo
    -Arun

  • How to create an item with date type mm/yyyy (no day)

    Hello,
    Is it possible to create an item with date type mm/yyyy (no day)? I want the pop-up date picker to just show month and year.
    Thanks,
    Jen

    Hi,
    you cannot pop-up date picker to just show month and year, but you can set your item format as MM-YYYY
    You can check this APEX_ITEM.DATE_POPUP2 at : http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_item.htm#CHDJHBCG (if using apex 4.1) else http://docs.oracle.com/cd/E10513_01/doc/apirefs.310/e12855/apex_item.htm#CHDFDDEI
    Edited by: Sergio_doudou on 2012-04-13 14:26

  • Selecting records from table A where A.date = max of date from table B

    Hi,
    I am new to OBIEE, How can I build the following Oracle query in OBIEE....
    select a.F1, a.F2, a.F3, a.date
    from Table1 a
    where a.date in
    (select max(b.date) from Table2 b where
    b.F1 = a.F1
    GROUP BY by b.F1)
    I tried Rank, Top, Aggregate however did not get the desired result.
    Thanks, Rohit

    You can create another request and use the results of that request as a Subquery in the filtering of the master request.

  • I want to change the date format MM/YYYY to MM.YYYY in web report

    Hi to all experts,
       Here  the problem is: when i run a report for variable input when we select date as MM/YYYY its getting error . Here i need to change MM/YYYY to MM.YYYY. can u please tell me where exactly i need to change means in BEx or Web? if it is BEx where it is exactly pls tell m ethe step to step procedure.
    Its urgent!
    ( I will assign the points if its useful to me)
    Advance Thanks,
    Shah

    Hi Siggi,
            In su01 if we go  and change the date format from MM/YYYY to MM.YYYY  for a particular user ex:ss11 , if another user ex:bst55 try to run the web report he/she may get same error .If we make the change in su01-> default tab->under date format for a particular user , is it work for other users?
    Can u tell me step by step where exactly we need to go in AWB and where need to modify.
    I am looking for ur answer.
    Thanks in Advance
    Shah

  • How can i get todays date as an yyyy-MM-dd format instead of Time stamp

    how can i get todays date as an yyyy-MM-dd format instead of Time stamp,i try to do it in the fallowing way
    <code>
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date d = new java.util.Date();
              String s = d+"";
    Calendar cal1 = Calendar.getInstance();
         try{
         cal1.setTime(sdf.parse(s));
    }catch(Exception e){}
    </code>
    but i could not able to get,it throws error as an java.text.ParseException: Unparseable date: "Thu Jan 24 11:43:32 EST 2002" ,pl suggest me any solution.any help would be appreciated.
    Regards.

    Does string s have to end with ""?
    Try doing sdf.format(d) instead.

  • Convertinf Date format from YYYY-MM-DD to MMDDYYYY

    Hi Experts,
              I want to convert  date format from yyyy-MM-dd  to MMDDYYYY ( i am using this format in the file strucure),
             i tryed using date tranfer funcion source as yyyy-MM-dd and target as yyyyMMdd this is working fine.
    i tryed using date tranfer funcion source as yyyy-MM-dd and target as MMddyyyy this is giving error.
    Please help me out,
    Thanks,
    Dhanush

    Hi,
    From the error it looks like the date value is coming as blank in the source. please give the date in the same format as you have provided in datetrans function and test it again. It will work.
    It might be possible that there are some other date fields in your source where you are not passing any value and using datefunction. please look carefully at all the source structure and data.
    thanks
    amit
    reward point if suggestion works

  • Date Validation In YYYY/MM/DD Format

    Hi All....
                I have developed A conversion Program in which I have struck up with the code of validating the date format in YYYY/MM/DD Format. I should Append the records to the database table T558B in which all the other validations are done. pls help me......

    Hi,
    Use in ABAP this sentence:
       SET COUNTRY t005x-land.
    In table T005X you have in field DATFM the formats for date. (or in tcode OY01)
    I hope this helps you
    Regards
    Eduardo
    Edited by: E_Hinojosa on Feb 14, 2011 5:08 PM

  • Input is 10 digit date (dd/mm/yyyy) some times instead of date they will se

    Hi Experts,
    requirement is
    input is 10 digit date (dd/mm/yyyy) some times instead of date they will send as space(10 digit). it should not fail in PI.
    kindly help me on this.
    regards
    Elton

    HI,
    I have given like
    if input equals to constant(space)
    then constant(space)----
    > here you have to pass constant date / system date
    else
    input
    input -> constant(10 space) -> equals ->if ->
    then -> constant(date) ->target
    else -> input->target filed
    thanks,

Maybe you are looking for

  • How to prevent user password being reset to the same password?

    Hi, As you all know, domain admin has the power to reset user password.  Let's think of the following scenario: if an admin lets a user reset his password to use the same string, this action means he could nullify company policy on password which req

  • I'm unable to sync my ipod nano

    This was a gift in January and I still have not been able to transfer from itunes to ipod nano after many many attempts and searches for assistance. As my first Apple device I'm really unimpressed - extremely slow on itunes which appears to clog up m

  • Sudden shutdown- then strange battery behavior?

    About a week ago I was using my 2009 Macbook before I went to take an exam. When I left it had very little battery left (it has given me a warning) but I just shut the top and left, figuring it would go into Safe-Sleep. When I came back, I found that

  • Lion does not recognizes the superdrive as external drive

    Hello, After having replaced my superdrive for a SSD in my macbook, I look for a solution to retrieve the original superdrive in Lion. the superdrive is now contained in a slim box firstcom. Each time i plug the drive via USB, it starts normally but

  • New FW upgrade - no apps will load anymore!?

    So i upgraded to the new FW several days ago (in hindsight it was a huge mistake) and now only two of my apps work- MySpace and Facebook as they released updates asap. I have 3 pages of Apps, NONE of which will open. I've downloaded apps recently tha