Oracle Bi Solutions

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 11 January 2013

Add days to a date (skipping Saturdays and Sundays)

Posted on 01:53 by Unknown

Question: I have managed to add days to a given date in a procedure. My question is how do I manipulate the procedure to skip weekends and holidays?
For example:
If the date is 19/9/2003 and I add 2 days, the resulting date should be 23/9/2003.
Answer: To skip weekends when adding days to a date, you will need to create a custom function. Below is a function that we've written called custom_add_days. It accepts two parameters - start_date_in and days_in.
This function takes the start_date_in value and adds the number of days in the days_in variable, skipping Saturdays and Sundays.
This function does not skip holidays as Oracle has no way of recognizing which days are holidays. However, you could try populating a holiday table and then query this table to determine additional days to skip.
CREATE OR REPLACE Function custom_add_days
(start_date_in date, days_in number)
return date
IS
v_counter number;
v_new_date date;
v_day_number number;

BEGIN

/* This routine will add a specified number of days (ie: days_in) to a date (ie: start_date). */
/* It will skip all weekend days - Saturdays and Sundays */
v_counter := 1;
v_new_date := start_date_in;

/* Loop to determine how many days to add */
while v_counter <= days_in
loop

/* Add a day */
v_new_date := v_new_date + 1;
v_day_number := to_char(v_new_date, 'd');

/* Increment counter if day falls between Monday to Friday */
if v_day_number >= 2 and v_day_number <= 6 then
v_counter := v_counter + 1;
end if;

end loop;

RETURN v_new_date;

EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in PL/SQL | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

Categories

  • BI Publisher
  • DAC
  • DataWarehouse
  • Hyperion
  • Informatica
  • OBIEE
  • ODI
  • Oracle Applications EBS 12.1.3
  • Oracle Database
  • PL/SQL
  • SQL
  • Unix/Linux

Blog Archive

  • ▼  2013 (500)
    • ►  November (8)
    • ►  October (1)
    • ►  July (4)
    • ►  June (9)
    • ►  May (15)
    • ►  April (24)
    • ►  March (43)
    • ►  February (73)
    • ▼  January (323)
      • Uninstalling Obiee 11g instance on a linux red hat
      • OBIEE 11g not showing new dashboard in the drop d...
      • OBIEE11g Installation
      • Starting OBIEE 11g Services on Linux
      • OBIEE11g Timestamp differencess
      • DAC11g Installation on Windows Server 2008R2.
      • BI Apps 7.9.6.4 Installation in widows server 2008R2
      • [OBIEE11g] - Eventually succeeded, but encountered...
      • [OBIEE11g] - Blue Screen Error While Login With Bi...
      • [OBIEE11g] - No Log Found Error
      • [OBIEE11g] - Stream Closed Error when Click on cor...
      • OBIA 7.9.6.4 RPD And Catalog Shared
      • [OBIEE11g] - Destination Path too Long error while...
      • [OBIEE11G] - Lookup table is a new feature in obie...
      • [OBIEE11g] - Create Veriable in OBIEE11g.
      • [OBIEE11g] - Configuring LDAP Server to provide OB...
      • [OBIEE11g] - Authentication Failure in OBIEE 11g
      • [OBIEE11g] - Bing Map Integration with OBIEE 11g
      • [OBIEE11g] - OBIEE Dashboard for Informatica Metad...
      • Informatica PowerCenter Upgrading from Version 8.6...
      • Data Modeling: Schema Generation Issue with ERwin ...
      • [OBIEE11g] - DAC Reporting in OBIEE11g
      • [OBIEE11g] - Publisher 11g – Performance Monitorin...
      • [OBIEE11g] - Auto Start OBIEE 11g using Windows Se...
      • [OBIEE11g] - Upgrade OBIEE 11.1.1.5 To Latest Vers...
      • OBIEE11g - User Right Click Interaction Control w...
      • [OBIEE11g] - Customizing Prompts ‘All Column Value...
      • [OBIEE11g] - Choosing the Right OBIEE Visualization
      • OBIEE11g - 11.1.1.6 New Features
      • [OBIEE11g] - Certification with Siebel Marketing f...
      • [OBIEE11g] - Creating a Stacked Bar Chart.
      • [BI EE11g] – Managing Host Name Changes
      • [DAC] - Multi Source Loads With OBIA
      • [Informatica] - ERROR CODES: [CNX_53021 ],[DOM_100...
      • [Informatica] - Informatica PowerCenter Repository...
      • [Informatica] - Processing UNICODE Characters in I...
      • [Linux] - Unix/Linix Commands
      • [DAC] - Full Load Vs Incremental Load
      • [Informatica] - Installation of Informatica 9.0.1 ...
      • [Informatica] - SF_34004- Service initialization ...
      • [Oracle Database] - Linux OS and Oracle database S...
      • [Oracle Database] - Installion Oracle database11g ...
      • [Informatica] - RR_4053 : Row error occurred while...
      • [OBIEE11g] - Change the placement of currency name
      • [OBIEE11g] - Exception Occuring During OBIEE 11.1....
      • What is Indexing in a Database
      • [OBIEE11g] - Setting up OBIEE11g Admin Tool for OD...
      • [OBIEE11g] - Getting Top-N Sales Reps Using the TO...
      • [OBIEE11g] - Getting Top-N Sales Reps Using Result...
      • [OBIEE11g] - Getting Top-N Sales Reps for Year and...
      • [OBIEE11g] - Analyzing Sales for “N Years Top-10 S...
      • [OBIEE11g] - Drill Down to Sub Reports Passing Mul...
      • [OBIEE11g[ - Configuring BI Scheduler for iBots on...
      • [OBIEE 11g] - How Application Roles, Groups and Us...
      • [OBIEE11g] - Setting up Access Permissions to Repo...
      • [OBIEE11g] - Fixing Weblogic and bi_server1 startu...
      • [OBIEE11g] - Deleting and Re-Creating Users in We...
      • [OBIEE 11g] - Backup and Restore of OBIEE Filesyst...
      • [OBIEE11g] - Creating Effective Bar Graphs
      • [OBIEE] - Useful SQL statements in Business Intell...
      • [OBIEE11g] - Creating Dashboard Traversing Throug...
      • [OBIEE11g] - Database Connection Failure while cr...
      • [DAC] - Admin password recovery
      • [Oracle 11g] - Oracle Database 11g installation on...
      • [OBIEE11g] - Variables in Oracle OBIEE 11g
      • [OBIEE11g] - Installing OBIEE 11g on Linux Fedora 17
      • [OBIEE11g] - Table view Date Column controlled by...
      • [OBIEE11g] - Adding Tooltips and conditional colo...
      • [OBIEE11g] - Show top-N Sales Persons in BI Publi...
      • [OBIEE11g] - Creating Scrolling Ticker Views
      • [OBIEE11g] - Authentication first with LDAP then ...
      • [OBIEE11g] - Relocation of OBIEE MetaData Reposit...
      • [OBIEE11g] - Hierarchical Roll-Up and Individual T...
      • [OBIEE11g] - Creation of Sales Reps Hierarchy wit...
      • [OBIEE11g] - Using external table to Filter BI Ans...
      • [OBIEE11g] - Configuring of RPD deployed on Linux...
      • [OBIEE11g] - Configuring an ODBC DSN for the Oracl...
      • [ODI] - Frequently Asked Questions (FAQ)
      • [OBIA] - Oracle BI Applications - Frequently Asked...
      • [OBIEE 11g] - Maps - Frequently Asked Questions (FAQ)
      • [OBIEE11g] - The 11g Features You Maybe Didn't Know!
      • [OBIEE11g] - New Features with OBIEE 11.1.1.6
      • [OBIEE11g] - Dashboard Prompt - "Prompt User"
      • [OBIEE11g] - [46153] The configuration file (O:\us...
      • [Informatica] - Multiple Chart of Accounts Configu...
      • [OBIEE11g] - Customizing Pivot Table Error
      • [OBIEE11g] - How to get Month Start Date and Month...
      • [OBIEE11g] - How to get Week Start Date and Week E...
      • [OBIEE11g] - How to rename My Dashboard
      • Table Organization in OBAW (Oracle Business Analyt...
      • [OBIEE11g] Uninstall OBIEE 11g
      • [OBIEE11g] - Command Line Merging in OBIEE 10g/11g
      • BI Publisher report is showing incorrect date(Show...
      • [OBIEE11g] - Connectivity issue from OBIEE (in Sol...
      • [OBIEE 11g] - Installation on Red Hat Linux
      • [OBIEE11g] - Different ToolTip for different rows ...
      • [OBIEE11g] - Integrating OBIEE 11g with EPM worksp...
      • [DAC] Fail to create indices during DAC execution ...
      • [DAC] Oracle DAC issue in 64 Bit Machine
      • [OBIEE11g] Connection Pool Select Button is Disabl...
      • [OBIEE11g] IE 9 Compatibilty
      • [OBIEE11g] Cannot connect to DB using OCI
      • [Informatica] Error : ora-01653 unable to extend t...
      • [Informatica] Informatica Service is not Configure...
      • [Informatica] PMCMD command line Syntax
      • [BI Apps] – Incorrect Quarter Ago Measures
      • [OBIEE11g] Hardware Requirements and Performance T...
      • [OBIEE11g] Waterfall Chart configuration
      • [OBIEE11g] Creating Action Link Menu
      • [OBIEE11g] Implementing Multiple Fact tables in Rpd
      • [OBIEE11g] Creating Users and Application roles an...
      • [OBIEE11g] Upgrade from 10g to 11g Step by Step
      • [OBIEE11g]How To Find Current Quarter With Out Usi...
      • [OBIEE11g] Time Series functions Ago And ToDate
      • [OBIEE] setting default dashboard page for Users
      • [OBIEE11G] Using Database Hints in RPD
      • [OBIEE11g] Dynamic Variables for Previous Date Period
      • [OBIEE 11g] Merging Two Repositories
      • [OBIEE11g] Upgrading BI Publisher 10.1.3.4.1 to OB...
      • [OBIEE 11g] BI Office Configuration
      • [OBIEE11g] Multimedia Dashboard In OBIEE 11G
      • [OBIEE11g] Web logic Starting Error "QTJava.zip wa...
      • [OBIEE11g] Feedback (Email) Link From OBIEE11g Das...
      • [OBIEE11g] Getting 30days back data from the selec...
      • [ODI] Installation in LINUX OEL 5.1
      • [OBIEE11g] Sorting a Measure Column in Pivot Table
      • [OBIEE11g] Ago Function in Answers
      • [OBIEE11g] Import Users from Weblogic to Rpd
Powered by Blogger.

About Me

Unknown
View my complete profile