/* Date functions in Oracle */

SELECT SYSDATE              /* dual is a dummy Oracle table, that is */
FROM   dual;                /* used when retrieving system variables */

SELECT MONTHS_BETWEEN(sysdate, '01-Jan-2024')                   /* date in correct format */
From   dual;

SELECT MONTHS_BETWEEN(sysdate, TO_DATE('01/01/24', 'mm/dd/yy'))
From   dual;

SELECT LAST_DAY('01-FEB-2024'), LAST_DAY('15-FEB-2025')         /* last day of month */ 
FROM   dual;

SELECT ADD_MONTHS('31-Mar-2024', -1)                            /* subtract 1 month */ 
FROM   dual;

SELECT MONTHS_BETWEEN('25-dec-2024', '15-mar-2021')             /* number of months between */
FROM dual;

SELECT TO_CHAR(sysdate, 'day, month  dd   yyyy')                /* convert date to string */
FROM dual;                      

SELECT TO_DATE('3/23/2024', 'mm/dd/yyyy')                       /* convert non-std date to date */
FROM dual;          

SELECT TO_DATE('6/3/2024 16:00:00', 'mm/dd/yyyy hh24:mi:ss')    /* convert non-std to date */ 
FROM dual;

SELECT sysdate + 20                                             /* add 20 days to date/time */
From   dual;

SELECT sysdate + 6/24                                           /* add 6 hours to date/time */ 
From Dual;

SELECT TO_DATE('6/3/24 16:00:00', 'mm/dd/yy hh24:mi:ss') + 5/(24*60) 
FROM dual;                                                      /* add 5 minutes to any date */

SELECT sysdate - TO_DATE('31-dec-24')                           /* days between */
FROM dual;                                                      /* now and end-of-year */