Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to convert months into weeks

syed haiderApr 26 2018 — edited May 3 2018

I have to split the first three months into weeks. All the weeks should end on saturday and start on friday.

Any suggestions as to how I can accomplish this? Following is my code;

dts as (

select date '2017-01-01' + rownum-1 dt

  from dual

  connect by level <= 366

),

rpt_fri_sat as

(

select dt,

        case when to_char(dt, 'fmday') = 'friday' then dt end fridays,

       case when to_char(dt, 'fmday') = 'friday' then rownum end fri_id,

        case when to_char(dt, 'fmday') = 'saturday' then dt end saturdays,

        case when to_char(dt, 'fmday') = 'saturday' then rownum end sat_id

from dts

where extract(month from dt) < 4

)

select *

from rpt_fri_sat

I want the output to display as follows;

1/1/18 to 1/5/18
1/6/18 to 1/12/18
1/13/18 to 1/19/18
1/20/18 to 1/26/18
1/27/18 to 2/2/18
2/3/18 to 2/9/18
2/10/18 to 2/16/18
2/17/18 to 2/23/18
2/24/18 to 3/2/18
3/3/18 to 3/9/18
3/10/18 to 3/16/18
3/17/18 to 3/23/18
3/24/18 to 3/30/18

Please let me know as to how I can accomplish this task. Any help would be greatly appreciated!

This post has been answered by mathguy on Apr 26 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2018
Added on Apr 26 2018
18 comments
1,692 views