How to convert months into weeks

  • 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? Thanks

  • First three months of what..? Perhaps you might want to consider investing in a Calendar table: http://www.sqlservercentral.com/articles/calendar/145206/

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • soldout6000 - Wednesday, April 25, 2018 8:14 PM

    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? Thanks

    What happens with weeks that include 2 different months?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • 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


    The problem is that I want to create appropriate Friday id and Saturday id. How could I do that and how could I get rid of the blank columns?

  • I can post a solution for this but it would work on SQL Server. You're working with Oracle, so you should check on an Oracle forum or http://stackoverflow.com/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply