Home > Blockchain >  Oracle previous month's 15 date?
Oracle previous month's 15 date?

Time:07-20

How can I get previous month's 15 date in a format YYYYMMDD?

CodePudding user response:

You can use TRUNC(SYSDATE, 'MM') to get the start of the current month and then add -1 months to get the previous month and then add 14 days (to go from the 1st to the 15th of the month) and then use TO_CHAR to apply the format you require:

SELECT TO_CHAR(
         ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1)   INTERVAL '14' DAY,
         'YYYYMMDD'
       ) AS dt
FROM   DUAL;

Which outputs:

DT
20220615

db<>fiddle here

  • Related