on 03-07-2019 9:23 PM
I am trying to get the last day in the previous month, I am using the using below SQL, it is giving the today's date in last month, but not the last day of the month.
SELECT ADD_MONTHS_LAST (CURRENT_DATE, -1) FROM DUMMY ;
I am not finding any difference of using, ADD_MONTHS() and ADD_MONTHS_LAST() with CURRENT_DATE.
the official documentation explaining an example, which has the last day in the date, so it does not explain behavior working,
do you know why this is? or I am missing something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sreekanth - For your requirement
Hi Sreekanth,
I think you need to use ADD_MONTHS_LAST and the code should be like below:
SELECT ADD_MONTHS_LAST(LAST_DAY(CURRENT_DAY), -1) FROM DUMMY;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it doesn't! ADD_MONHTS gives you exact date of the reference input date.
For example 2019-03-08 becomes 2019-04-08 with 1 or 2019-02-08 with -1.
Your need is getting the last day of the month, so you need to use ADD_MONTHS_LAST
Have you tried it below?
SELECT ADD_MONTHS_LAST(LAST_DAY(CURRENT_DAY),-1)FROM DUMMY;
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.