In your session, the NLS_DATE_FORMAT is DD-MM-YYYY.
There are 86400 seconds in a day.
Examine this result:
DATE -
-----------
02-JAN-2020
Which statement returns this?
In your session, the NLS_DATE_FORMAT is DD-MM-YYYY.
There are 86400 seconds in a day.
Examine this result:
DATE -
-----------
02-JAN-2020
Which statement returns this?
The provided date format is DD-MM-YYYY. Starting with 29-10-2019, adding an interval of 2 months results in 29-12-2019. Adding an interval of 5 days brings us to 03-01-2020. Subtracting 120 seconds (2 minutes) gives us 02-01-2020. Therefore, the correct option is the one that represents this calculation accurately.
Option C is the statement that returns the result 02-JAN-2020. The statement converts the string '29-10-2019' to a date using the TO_DATE function, then adds an interval of 2 months and an interval of 5 days, and subtracts an interval of 120 seconds. The resulting date is then converted to a string using the TO_CHAR function with the format model 'DD-MON-YYYY', which produces the result 02-JAN-2020. Here is the calculation: TO_DATE('29-10-2019') = October 29, 2019 + INTERVAL '2' MONTH = December 29, 2019 + INTERVAL '5' DAY = January 3, 2020 - INTERVAL '120' SECOND = January 2, 2020
Correct answer should be SELECT TO_CHAR(TO_DATE('29-OCT-2019') + INTERVAL '2' MONTH + INTERVAL '5' DAY - INTERVAL '120' SECOND, 'DD-MON-YYYY') AS "date" FROM DUAL;
NLS_DATE_FORMAT is DD-MM-YYYY
C because: when we add INTERVAL '2' MONTH + INTERVAL '5' DAY to 29-10-2019, we get 03-01-2020, as of midnight, and then we subtract - INTERVAL '120' SECOND i.e. 2 minutes, hence we get answer as '02-JAN-2020'
C is correct after testing, although I don't know why it is INTERVAL '5' instead of '4'.
its 5 cause we are substracting the seconds from the 5th day.
THIS. It's easy to read over the minus operator. Also the way this is written gives ORA-01843 error. Correct syntax would be: SELECT to_char(to_date ('29-10-2019', 'DD-MM-YYYY') + INTERVAL '2' MONTH + INTERVAL '5' DAY - INTERVAL '120' SECOND, 'DD-MM-YYYY') AS "date" FROM dual;
No error just do ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
note to self: study the calendar to know when months end, because if Dec ends on 30 instead of 31, the answer would've been A or D