Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

How to get the last non weekend day of a month

syparth-JavaNetFeb 18 2014 — edited Feb 18 2014

Hello All,

Is the below query appropriate and best to use to get the last working day of the month ?

SELECT to_date('13.08.2014','dd.mm.yyyy') + MAX(RNUM) LastDay(nonweekend)

   FROM   (SELECT ROWNUM RNUM

          FROM   ALL_OBJECTS where rownum <=31)

  WHERE   ROWNUM <= 31 ANd

     TO_CHAR(to_date('13.08.2014','dd.mm.yyyy') + RNUM, 'DY','NLS_DATE_LANGUAGE=ENGLISH' ) NOT IN ('SAT' , 'SUN')

     and to_date('13.08.2014','dd.mm.yyyy') + RNUM <= last_day(to_date('13.08.2014','dd.mm.yyyy'))

I have to use this query in production.

Is this advisable to use ?

This post has been answered by GregV on Feb 18 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2014
Added on Feb 18 2014
6 comments
525 views