Home > Ask the Oracle Database / Applications Experts > Questions & Answers > Checking the day of the week
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Checking the day of the week

Frank Kulash EXPERT RESPONSE FROM: Frank Kulash

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 24 October 2003
I need to determine if a particular day of the week exists between two given dates. I can't figure out an elegant way to do this, only comparing every DOW between the two dates to DOW in question. Is there an Oracle DATE function that does this? I need this check to be as quick as possible, as it is built into a form.

>
There is an Oracle function, NEXT_DAY, that you can use in a fairly elegant solution.
CREATE OR REPLACE FUNCTION dow_between
(
    in_dow_text  VARCHAR2,   -- e.g. 'Mon' or 'Monday'
    in_date_1    DATE,       -- starting date
    in_date_2    DATE        -- ending date
)
RETURN  DATE

--  *****************************
--  **  d o w _ b e t w e e n  **
--  *****************************

--  dow_between returns the a DATE between in_date_1 and
--  in_date_2 whose day-of-the week matches in_dow_text.
--  dow_between returns NULL if there is no such date.
--  in_date_1 must be earlier than in_date_2.

--  Example: dow_between ('SAT', SYSDATE, due_dt)
--  checks if there is a Saturday between today and due_dt,
--  inclusive.  If there is, it returns the DATE of the first
--  one.  If not, it returns NULL.

--  in_dow_text can be any unique abbreviation (case insensitive)
--  of the day-of-the-week in NLS_LANGUAGE.

IS
    return_date  DATE := NEXT_DAY ( in_date_1 - 1,
                                    in_dow_text
                                  );
BEGIN
    IF  TRUNC (return_date) > in_date_2
    THEN
        return_date := NULL;
    END IF;

    RETURN  return_date;
END  dow_between;
/

The NEXT_DAY (d, c) function has a couple of quirks that dow_between handles or inherits:


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts