Home » SQL & PL/SQL » SQL & PL/SQL » get 7 working day excluding holidays in Oracle (Oracle 11g)
get 7 working day excluding holidays in Oracle [message #645293] Wed, 02 December 2015 07:42 Go to next message
manoj12
Messages: 210
Registered: March 2008
Location: India
Senior Member
Hi Sir,

I wanted to get the date of 7th working day of a month excluding holidays(it also excludes saturday and sunday) and in Oracle.

for e.g Lets take an example of Dec-2015 month.The 7th working date of a month of december 2015 excluding saturday and sunday is 9-12-2015.It should return me this date.

Please appreciate your help?

Regards,

[Updated on: Wed, 02 December 2015 07:44]

Report message to a moderator

Re: get 7 working day excluding holidays in Oracle [message #645294 is a reply to message #645293] Wed, 02 December 2015 07:44 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Oracle doesn't know when you go on holiday. You need to develop an algorithm for determining what is a working day.
Re: get 7 working day excluding holidays in Oracle [message #645295 is a reply to message #645293] Wed, 02 December 2015 07:45 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
manoj12 wrote on Wed, 02 December 2015 05:42
Hi Sir,

I wanted to get 7th business day of a month excluding holidays in Oracle.

Please appreciate your help?

Regards,

Solution requires table containing Holiday dates.

Can you write SQL when you don't know table name & column names? I can't.


Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read


Re: get 7 working day excluding holidays in Oracle [message #645296 is a reply to message #645295] Wed, 02 December 2015 07:48 Go to previous messageGo to next message
manoj12
Messages: 210
Registered: March 2008
Location: India
Senior Member
Hi Sir,

I need to write a function to get 7th working day in a month.

How to return 7th working day of a month.

Regards,

[Updated on: Wed, 02 December 2015 07:48]

Report message to a moderator

Re: get 7 working day excluding holidays in Oracle [message #645297 is a reply to message #645296] Wed, 02 December 2015 07:49 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
What is a working day? My weekend is Saturday/Sunday, but a couple of billion people have it on Friday/Saturday.
Re: get 7 working day excluding holidays in Oracle [message #645298 is a reply to message #645296] Wed, 02 December 2015 07:54 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
manoj12 wrote on Wed, 02 December 2015 05:48
Hi Sir,

I need to write a function to get 7th working day in a month.

How to return 7th working day of a month.

Regards,


Nobody here prevents you from writing any function you desire.
So start writing a function if you require a solution.
Re: get 7 working day excluding holidays in Oracle [message #645299 is a reply to message #645298] Wed, 02 December 2015 08:13 Go to previous messageGo to next message
manoj12
Messages: 210
Registered: March 2008
Location: India
Senior Member
Hi Sir,

My weekend is saturday and sunday and the working day is from Monday to Friday.

Regards
Re: get 7 working day excluding holidays in Oracle [message #645300 is a reply to message #645299] Wed, 02 December 2015 08:15 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Solution requires table containing Holiday dates, which we don't have.
Do you?
Re: get 7 working day excluding holidays in Oracle [message #645304 is a reply to message #645293] Wed, 02 December 2015 09:29 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Don't mind, but, on a serious note, you have been with OraFAQ since 6+ years, and you posted such a low quality question.

Neither did you provide the required code as a working test case, nor did you clearly show your desired output.

Also, it is a FAQ. Did you at least search the web before posting? No problem, if you couldn't get anywhere near, you could show us what have you tried so far.

If you don't want to be treated as a newbie here after 6+ years, then please make some effort. It would help you, not me.

Quote:
The 7th working date of a month of december 2015 excluding saturday and sunday is 9-12-2015


Why? What's the rule? As asked by others already, what do you mean by a working day? I work everyday, and my calendar has 7 working days a week just like any other day of the week Razz

[Updated on: Wed, 02 December 2015 09:46]

Report message to a moderator

Re: get 7 working day excluding holidays in Oracle [message #645306 is a reply to message #645293] Wed, 02 December 2015 09:44 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
So, what have you come up with so far, Manoj?
It should be clear to you that you need a table of non-work days, populated with your holidays and weekends.

Then you could (just one solution) create a table with all the days and use a compound query (think MINUS) to extract the working days. Then use a query against that with a predicate to extract the month you want, and another query against that with ha ROWNUM predicate to get the seventh working day.
You can do it all in one statement with a couple of in-line views, or using a WITH common table expression clause.
Re: get 7 working day excluding holidays in Oracle [message #645308 is a reply to message #645299] Wed, 02 December 2015 11:17 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

If your holidays are just week-end days then you can use:
SQL> select to_char(dt,'Dy DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') dt
  2  from ( select trunc(sysdate,'MONTH')+level- 1 dt,
  3                row_number() over (order by level) rn
  4         from dual
  5         where to_char(trunc(sysdate,'MONTH')+level- 1,'Dy','NLS_DATE_LANGUAGE=AMERICAN')
  6               not in ('Sat','Sun')
  7         connect by level <= 11 )
  8  where rn = 7
  9  /
DT
---------------
Wed 09-DEC-2015

If you have other holidays, then you have to add a new table with all these holidays as others mentioned.
The exclusion can be made in the same way than in my query, just changing what is between () in line 6 (and maybe the 11 in line 7, I let you find the general way to write it).

[Updated on: Wed, 02 December 2015 11:18]

Report message to a moderator

Previous Topic: Query
Next Topic: Date issues
Goto Forum:
  


Current Time: Thu Apr 25 16:02:43 CDT 2024