Select Mondays between two date

Hello world
I need select Monday between 2 date for ex. date_beg is the start date, date_end is the end date
so
DECLARE
data_beg DATE: = TO_DATE (January 6, 2011 ', 'dd-mm-yyyy');
DATA_END block DATE: = TO_DATE (July 31, 2011 ', 'dd-mm-yyyy');
mon_day DATE;
BEGIN
{code}

DBMS_OUTPUT. Put_line (mon_day);
end;

Wait your answers
THX

Like this...

SQL> ed
Wrote file afiedt.buf

  1  with t as (select TO_DATE('01-06-2011', 'dd-mm-yyyy') as start_dt
  2                   ,TO_DATE('31-07-2011', 'dd-mm-yyyy') as end_dt
  3             from dual)
  4  --
  5  select start_dt+rn-1 as dt
  6  from t, (select rownum as rn from t connect by rownum <= (end_dt-start_dt)+1)
  7* where to_char(start_dt+rn-1,'fmDay') = 'Monday'
SQL> /

DT
-----------
06-JUN-2011
13-JUN-2011
20-JUN-2011
27-JUN-2011
04-JUL-2011
11-JUL-2011
18-JUL-2011
25-JUL-2011

8 rows selected.

Tags: Database

Similar Questions

  • How to alternate Mondays between two dates?

    Hello

    I try to get the dates for other occurrences of a given day (say Monday) in a given range of dates.  How is it possible in a SQL query? Thanking you in advance.

    Hello

    Here's one way:

    WITH params AS

    (

    SELECT NEXT_DAY (TO_DATE (February 7, 2014 ', 'DD-Mon-YYYY') - 1).

    , 'MONDAY '.

    ) AS start_date

    , TO_DATE (31 March 2014 ', 'DD-Mon-YYYY') AS end_date

    OF the double

    )

    Start_date SELECT + ((LEVEL-1) * 14) AS a_date

    OF params

    CONNECT BY LEVEL<= ceil="" ((end_date="" +="" 1="" -="" start_date)="">

    ;

    Of course, you can easily change start_date and end_date and the day of the week target also, to all you want.

    This assumes that NLS_DATE_LANGUAGE = ENGLISH.  If you can not sure about NLS_DATE_LANGUAGE, then the same basic idea works, but the function calls are a bit messier.

    I hope that answers your question.

    Otherwise, put one or two series of the summer (start_date, end_date, day_o_week) and the desired results of each set.  Point where the above query was to produce erroneous results, and explain how to get good results in these places.

  • photo selection between two dates

    In Photos

    It is possible to select photos between two dates?

    In Photos,.

    is it possible to select the photos between two dates?

    Thank you, thank you

    Yes.  With a smart album like this:

  • Select the mountains between two dates

    Hi all
    How can I select all months between two dates. For example, if two dates are say 2008-05-25 and 2009-07-15, then I need following output

    May-2008
    June-2008
    July-2008
    August-2008
    September-2008
    October-2008
    November-2008
    December-2008
    January-2009
    February-2009
    March-2009
    April-2008
    May-2009
    -June 2009
    July-2009

    Thank you
    Sujnan

    Try this one

    SQL>  SELECT TO_CHAR(add_months(TRUNC(to_date('25/05/2008','DD/MM/YYYY'),'MM') ,(level-1)),'fmMonth-YYYY')
      2     FROM dual
      3    CONNECT BY level <= months_between(to_date('15/07/2009','DD/MM/YYYY'),to_date('25/05/2008','DD/MM/YYYY')) + 2;
    
    TO_CHAR(ADD_MO
    --------------
    May-2008
    June-2008
    July-2008
    August-2008
    September-2008
    October-2008
    November-2008
    December-2008
    January-2009
    February-2009
    March-2009
    
    TO_CHAR(ADD_MO
    --------------
    April-2009
    May-2009
    June-2009
    July-2009
    
    15 rows selected.
    
    SQL> 
    
  • Number of Saturdays between two dates

    Hello

    How can I get number of Saturdays between two dates, including the two dates?

    for example number of Saturdays between 09/05/2014 and 10/05/2014 is five

    Help, please

    I use oracle 10g

    SQL> with t
      2  as
      3  (
      4  select to_date('05/09/2014 ', 'dd/mm/yyyy') from_dt
      5       , to_date('05/10/2014 ', 'dd/mm/yyyy') to_dt
      6    from dual
      7  )
      8   select to_char(from_dt + (level-1), 'fmDay') day_
      9        , count(*) cnt
     10     from t
     11  connect
     12       by level <= to_dt - from_dt + 1
     13    group
     14       by to_char(from_dt + (level-1), 'fmDay');
    
    DAY_             CNT
    --------- ----------
    Saturday           5
    Thursday           4
    Tuesday            4
    Friday             5
    Wednesday          4
    Monday             4
    Sunday             5
    
    7 rows selected.
    
    SQL>
    
  • Calculate the hours between two dates

    Hello

    I have a requirement to count the hours with 2 given timestamps, something like:
    SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ;
    
             B
    ----------
            48
    However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).
    So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
    How can I achieve this? Any idea will be useful.

    Thank you

    My query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.

    There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).

    Ben

  • Dynamic calculation of the number of days between two dates in a table

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    Hi BO123,

    BO123 wrote:

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    one of the way to do this by calling ajax on change of end_date.

    See the sample code given below to fetch the resulting duration and making the field read only after calculation

    Step 1: Change your page

    under CSS-> Inline, put the code below

    .row_item_disabled {
      cursor: default;
      opacity: 0.5;
      filter: alpha(opacity=50);
      pointer-events: none;
    }
    

    Step 2: Create on demand Ajax process I say CALC_DURATION

    Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call

    Declare
      p_start_date  date;
      p_end_date    date;
      p_duration number;
    Begin
      p_start_date  := to_date(apex_application.g_x01);
      p_end_date    := to_date(apex_application.g_x02);
    
       --do your calculation and assign the output to the variable p_duration
      select p_end_date - p_start_date into p_duration
        from dual;
    
      -- return calculated duration
      sys.htp.p(p_duration);
    End;
    

    Step 3: Create the javascript function

    Change your page-> the function and the declaration of the Global Variable-> put the javascript function

    You must extract the rowid in the first place, for which you want to set the time, see line 2

    assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration

    See no line no 8 how set the value returned by the process of ajax at the duration column

    Replace your column to the respective column identifiers in the code below

    function f_calulate_duration(pThis) {
      var row_id  = pThis.id.substr(4);
      var start_date = $('#f06_'+row_id).val();
      apex.server.process ( "CALC_DURATION", {
      x01: start_date,x02: $(pThis).val()
    }, { success: function( pData ) {
    // set duration to duration column
    $('#f08_'+row_id).val(pData);
    // disable duration column
    $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); }
    });
    }
    

    Step 4: choose the end date call the javascript function

    Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below

    onchange="javascript:f_calulate_duration(this);"
    


    hope this helps you,

    Kind regards

    Jitendra

  • difference between two dates in the year/month/day in Obiee

    Hi gurus,

    I know this question have been asked and answered several times but I have a requirement that is a little different, then the previous ones.

    I want to calculate the difference between two dates in OBIEE10g in year/month/day format similar to the below SQL output

    SQL > select end_date, start_date,

    trunc (months_between (end_date, start_date) / 12) years.

    months of mod (trunc (months_between (end_date, start_date)), 12).

    End_date - add_months (start_date, trunc (months_between (end_date, start_date))) days

    t

    Thanks in advance

    SK

    Search for this

    "TIMESTAMPDIFF IN THE FORM OF MTHS # YEARS."

    or else

    To get the current mandate of employees since the date of hiring in the form of # years # mths or # year (s) # month (s)

    Concat (concat (cast (TIMESTAMPDIFF (SQL_TSI_Month, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) / 12 as char),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Month (s)'))

    Concat (concat (CAST (TIMESTAMPDIFF (SQL_TSI_YEAR, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) as CHAR),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Mth (s)'))

  • Days between two dates given

    Hi all

    I need the days between two dates given.

    Select to_date('25-mar-2014','dd-mon-yyyy') start_date, end_date to_date('30-mar-2014','dd-mon-yyyy')

    of the double

    Desired output:

    25

    26

    27

    28

    29

    30

    Thanks in advance.

    Kind regards

    Afzal.

    Select the level - 1 desired_output + to_number (to_char (start_date, 'dd'))

    of (to_date('25-mar-2014','dd-mon-yyyy') select start_date, end_date to_date('30-mar-2014','dd-mon-yyyy'))

    of the double

    )

    connect by level<=  end_date="" -="" start_date="" +="">

    DESIRED_OUTPUT
    25
    26
    27
    28
    29
    30

    Concerning

    Etbin

  • Months between two dates

    Hello

    I have two dates. start date and end date.

    I want to extract months between two dates

    months should be as

    JAN

    FEB

    MAR

    for example.

    Start - 1-jan-2014

    date of end - 31 - dec - 2014

    How can I do this?

    Thanks and greetings

    CORINE

    You should always use the function MONTHS_BETWEEN...

    for example

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5. Select to_char (add_months (start_date, rownum-1), 'My') by month
    6 t
    7 * connect by rownum<=>
    SQL > /.

    LUN
    ---
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Ms
    Oct
    Nov
    Dec

    12 selected lines.

    And if you want that they display, separated by commas...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5 Select listagg (to_char (add_months (start_date, rownum-1), 'My'), ',') group by month (order by rownum)
    6 t
    7 * connect by rownum<=>
    SQL > /.

    MONTH
    -----------------------------------------------------------------------------------------------------------------
    Jan, Feb, Mar, Apr, may, June, July, August, Sept, Oct, Nov, Dec

  • Number of occurrences of a day between two dates

    Hello

    I have a requirement in my code to count the number of times per day occurs between two dates. So, for example if

    start date = January 1, 2014

    end date = March 31, 2014

    The number of times that happens day 1 is three times. That's why I want the result to be 3. My three input parameters are the number of the day, start and end dates. I know that this can be done by parsing through the days and incrementing a counter of sorts, but can it be done without any loop etc?

    Looking for options of

    Thank you

    Birdy

    SELECT COUNT (TO_CHAR (DAYS, 'DD')) IN)

    SELECT DAYS START_DATE + LEVEL 1

    FROM T1

    CONNECT BY LEVEL<=>

    WHERE TO_CHAR (DAYS, 'DD') ='&01';

    Post edited by: Parth272025

  • How to find days between two dates in days

    Hi, I want to get the days between two dates, expressed in days, how can I do this?  For example, I date i.e. 1 October 10, 2013 (Thursday) and 2 as October 13, 2013 (Sunday).  How can I get a production of:

    Thursday, Friday, Saturday and Sunday, which are the days between Oct. 10-13, 2013.  I hope you understand my point.  Thank you

    You can try something like this

    CURSOR LOAD_PROF is

    SELECT load_prof1, v_time_profile_day

    OF load_profile_test

    WHERE profile_day IN (select TO_CHAR(:day1+level-1,'Day')

    of the double

    connect by level<>

    );

    Kind regards

    S Pax

  • Number of weeks between two dates that are in the same or different year

    Hello

    How to calculate the number of weeks between two dates?

    for example. "" "17-mar-2013' and June 27, 2013" or June 15, 2013 "and" 25-mar-2014


    Thanks in advance.

    lukx

    Hello

    Looks like your date range is incorrect.

    Please try the below.

    SQL >-front right

    SQL > select D2 - D1 "days."

    2 round ((D2-D1)/7.0) "weeks."

    3 round (Months_between (d1, d2), 0) 'months '.

    (select 4

    5 TO_DATE ('20121201', 'YYYYMMDD') D1, D2 TO_DATE ('20130116', 'YYYYMMDD')

    6 from two

    (7) date_range;

    Elapsed days weeks months

    ------------ --------- ---------

    46         7         1

  • Calculate business hours between two dates in a cursor

    Hello, its me again (?).

    Yesterday, I got a solution to a problem here where I need to calculate the hours between two dates, excluding Sat/Sun and from 09:00 to 18:00. I'm now putting this login in a PL/SQL block, so I can calculate it for each record in a slider, all by looping.
    with t (start_date
           ,end_date
           )
    as (select  to_date('22-oct-2012 09:00:00','dd-mon-yyyy hh24:mi:ss') start_dt,
                           to_date('23-oct-2012 09:00:00','dd-mon-yyyy hh24:mi:ss') end_dt
        from dual
       )
    , hrs (dt) as
      (select start_date
       from   t
       union all
       select dt +1/24/60
       from   hrs
       where  hrs.dt < (select end_date-1/24/60 from t)
      )
    select count(*)/60
    from hrs
    where to_char(dt,'dy') not in ('sat','sun')
    and  to_number(to_char(dt,'hh24')) not between 18 and 23
    and  to_number(to_char(dt,'hh24')) not between 0 and 8
    /
    The logic above, I'm up here:
    FOR c_record IN c_1 LOOP
    //For each record, check if the two dates meet the criteria and then raise the counters accordingly
    select  to_date(c_record.REPORTADA,'dd-mon-yyyy hh24:mi:ss') INTO vFch1 FROM DUAL;
    SELECT  to_date(c_record.INICIOREAL,'dd-mon-yyyy hh24:mi:ss') INTO vFch2 FROM DUAL;
    
    IF ((vHoras > 2) AND c_record.PRIORIDAD=3) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE 
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END
        IF;
    
    IF ((vHoras > 4) AND c_record.PRIORIDAD=2) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END IF;
    
    IF ((vHoras > 16) AND c_record.PRIORIDAD=1) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END IF;
    
    END LOOP;
    I really don't like if the performance is horrible because it will run once a month and should spend only 40-100 records.
    However, I can't find a way to use this connection even in this case

    Could you help me?
    Thank you!

    Greetings,
    NACEUR

    N wrote:
    I need to calculate the number of minutes between two dates, only count the hours from 9 to 18hs.

    CREATE OR REPLACE
      FUNCTION get_bus_minutes_between(
                                       p_start_date DATE,
                                       p_end_date DATE
                                      )
        RETURN NUMBER
        IS
            v_return NUMBER;
        BEGIN
            with t as (
                       select  case level
                                 when 1 then greatest(p_start_date,trunc(p_start_date) + 9 / 24)
                                 else trunc(p_start_date) + level - 15 / 24
                               end start_dt,
                               case connect_by_isleaf
                                 when 1 then least(p_end_date,trunc(p_end_date) + 18 / 24)
                                 else trunc(p_start_date) + level - 8 / 24
                               end end_dt
                         from  dual
                         connect by level <= trunc(p_end_date) - trunc(p_start_date) + 1
                      )
            select  sum(greatest(end_dt - start_dt,0)) * 24 * 60 work_minutes
              into  v_return
              from  t
              where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- exclude weekends
            RETURN v_return;
    END;
    /
    

    For example:

    SQL> select get_bus_minutes_between(
      2                                 to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'),
      3                                 to_date('22-oct-2012 13:21:00','dd-mon-yyyy hh24:mi:ss')
      4                                ) work_minutes
      5    from dual
      6  /
    
    WORK_MINUTES
    ------------
             261
    
    SQL> 
    

    SY.

  • How do the time difference between two dates?

    Hi all

    I use this query to get the time difference between two dates.

    Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;

    but do not get the correct result.

    Thank you

    Left KEY... Left Padding of tanks.

Maybe you are looking for