-
Need Last Months Start and End Dates
Hi,
Anyone have a simple solution to generate last months start and end dates ?
For example, today is 12-Nov-2003, I need 01-Oct-2003,31-Oct-2003.
If today is 01-Jan-2003, I need 01-Dec-2002,31-Dec-2002
I've got a solution but its messy i.e., tochar(todate(tochar)) etc..
-
Code:
SQL> l
1 select sysdate,
2 trunc(sysdate,'MM')-1 end_last_month,
3 trunc(trunc(sysdate,'MM')-1,'MM') start_last_month
4* from dual
SQL> /
SYSDATE END_LAST_ START_LAS
--------- --------- ---------
12-NOV-03 31-OCT-03 01-OCT-03
Jeff Hunter
-
or better yet...
Code:
SQL> l
1 select sysdate,
2 last_day(add_months(sysdate, -1)) end_last_month,
3 trunc(add_months(sysdate, -1), 'MM') start_last_month
4* from dual
SQL> /
SYSDATE END_LAST_ START_LAS
--------- --------- ---------
12-NOV-03 31-OCT-03 01-OCT-03
Jeff Hunter
-
Thanks Jeff.
I had
select '01'|| substr(to_char(to_date(to_char(sysdate,'mmyy'),'mmyyy')-1,'dd/mm/yyyy'),3) ,
to_char(to_date(to_char(sysdate,'mmyy'),'mmyyy')-1,'dd/mm/yyyy')
from dual
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|