Get number of month, week and date between 2 dates

Hi all,
Is it possible to display number of month, week and days between 2 dates? either by using only SQL query or through PL/SQL...
Input:
From date: 01-Oct-2010
To date: 19-Oct-2010
I want output as below (Assuming the week starts from Monday to Sunday in oracle).
01-Oct-2010 -- (Since this is in mid of the week)
02-Oct-2010 -- (Since this is in mid of the week)
03-Oct-2010 -- (Since this is in mid of the week)
40 -- (Oct 4 to Oct 10 falls in 40th week of the year)
41 -- (Oct 11 to Oct 17 falls in 41th week of the year)
18-Oct-2010 -- (Since this is in mid of the week)
19-Oct-2010 -- (Since this is in mid of the week)
Note: If there is one full month between the given date, then the month number should be displayed.
After the month, the remaining date comprised with one full week, then the week number of the year should
be displayed. After displaying the week, the remaining dates should be displayed as it is..
Appreciate your help..
Thanks.
Rajan.

I suppose if it's just like a calendar type information you want then something like...
SQL> break on month skip 1
SQL> set linesize 200
SQL> set pagesize 2000
SQL> column month format a20
SQL> column week format a4
SQL> with req as (select '&Required_Year_YYYY' as yr from dual)
  2      ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req
  3  select lpad( Month, 20-(20-length(month))/2 ) month,
  4         '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
  5  from (
  6    select to_char(dt,'fmMonth YYYY') month,
  7    case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
  8         when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
  9         when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
10         else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
11    max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Mo",
12    max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Tu",
13    max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "We",
14    max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "Th",
15    max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Fr",
16    max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Sa",
17    max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Su"
18    from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
19           from all_objects, req
20           where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
21        ,offset
22    group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
23                                                  when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
24                                                  when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
25                                                  else to_char(to_number(to_char(dt,'iw'))+offset) end
26    ) x
27  order by to_date( month, 'Month YYYY' ), to_number(x.week)
28  /
Enter value for required_year_yyyy: 2010
old   1: with req as (select '&Required_Year_YYYY' as yr from dual)
new   1: with req as (select '2010' as yr from dual)
MONTH                WEEK Mo Tu We Th Fr Sa Su
    January 2010     (1)               1  2  3
                     (2)   4  5  6  7  8  9 10
                     (3)  11 12 13 14 15 16 17
                     (4)  18 19 20 21 22 23 24
                     (5)  25 26 27 28 29 30 31
   February 2010     (6)   1  2  3  4  5  6  7
                     (7)   8  9 10 11 12 13 14
                     (8)  15 16 17 18 19 20 21
                     (9)  22 23 24 25 26 27 28
     March 2010      (10)  1  2  3  4  5  6  7
                     (11)  8  9 10 11 12 13 14
                     (12) 15 16 17 18 19 20 21
                     (13) 22 23 24 25 26 27 28
                     (14) 29 30 31
     April 2010      (14)           1  2  3  4
                     (15)  5  6  7  8  9 10 11
                     (16) 12 13 14 15 16 17 18
                     (17) 19 20 21 22 23 24 25
                     (18) 26 27 28 29 30
      May 2010       (18)                 1  2
                     (19)  3  4  5  6  7  8  9
                     (20) 10 11 12 13 14 15 16
                     (21) 17 18 19 20 21 22 23
                     (22) 24 25 26 27 28 29 30
                     (23) 31
     June 2010       (23)     1  2  3  4  5  6
                     (24)  7  8  9 10 11 12 13
                     (25) 14 15 16 17 18 19 20
                     (26) 21 22 23 24 25 26 27
                     (27) 28 29 30
     July 2010       (27)           1  2  3  4
                     (28)  5  6  7  8  9 10 11
                     (29) 12 13 14 15 16 17 18
                     (30) 19 20 21 22 23 24 25
                     (31) 26 27 28 29 30 31
    August 2010      (31)                    1
                     (32)  2  3  4  5  6  7  8
                     (33)  9 10 11 12 13 14 15
                     (34) 16 17 18 19 20 21 22
                     (35) 23 24 25 26 27 28 29
                     (36) 30 31
   September 2010    (36)        1  2  3  4  5
                     (37)  6  7  8  9 10 11 12
                     (38) 13 14 15 16 17 18 19
                     (39) 20 21 22 23 24 25 26
                     (40) 27 28 29 30
    October 2010     (40)              1  2  3
                     (41)  4  5  6  7  8  9 10
                     (42) 11 12 13 14 15 16 17
                     (43) 18 19 20 21 22 23 24
                     (44) 25 26 27 28 29 30 31
   November 2010     (45)  1  2  3  4  5  6  7
                     (46)  8  9 10 11 12 13 14
                     (47) 15 16 17 18 19 20 21
                     (48) 22 23 24 25 26 27 28
                     (49) 29 30
   December 2010     (49)        1  2  3  4  5
                     (50)  6  7  8  9 10 11 12
                     (51) 13 14 15 16 17 18 19
                     (52) 20 21 22 23 24 25 26
                     (53) 27 28 29 30 31
61 rows selected.
SQL>

Similar Messages

  • Default selection on current month, week and date

    Hi,
    We are on Dashboard 4.1 sp3 the same version as BI.
    The dashboard report is using LiveOffice connection. We are now facing an issue with default selection on current month, week and date.
    The dashboard report drilled down from month, to week, then to date. The dashboard feed -live office report is on month/week/date ascending order - becuase we have running average calcualtion on LO report, it seems have to be in ascending order to get the correnct runnning average.
    I tried to on Insertion to change default seletion, it works on month, but it doesnt working on week and daily.
    but when LO report is on ascending order, on dashboard column chart the default selection is not on the current month, week and date.
    Is there a way to solve the issue. Could anyone please help.
    Thanks,

    Hi Suman,
    Thanks for the quick reply.
    Do you mean I Enable sorting -by categrory labels on Behaviour - common tab.
    Thanks,

  • Find date if year, month, week and day is given

    Hi,
    How to find the date, if year, month, week and day is given?
    For example:
    Given, year - 2010, month - 03, Day - Wednesday, Week - 3,
    Then how can we get the date as 17-Mar-2010.
    Thanks,
    Chris

    with dt_tbl as (
                    select  2010 year,
                            3 month,
                            3 week,
                            'Wednesday' day
                      from  dual
    select  trunc(to_date(year || '-' || month || '-01','yyyy-mm-dd'),'iw') + (week - 1) * 7 +
              case day
                when 'Monday' then 0
                when 'Tuesday' then 1
                when 'Wednesday' then 2
                when 'Thursady' then 3
                when 'Friday' then 4
                when 'Saturday' then 5
                when 'Sunday' then 6
              end dt
      from  dt_tbl
    DT
    17-MAR-10
    SQL> SY.

  • Query to get number of invoice created by user between from and to date

    Dear All
    I need Query to get number of invoice created by user on day and his orgainization between from and to date.
    thanks

    select count(*) from ap_invoices_all where created_by = :p_User_id
    and trunc(creation_date) between :p_from_date and :P_to_date;
    Thanks/SRK

  • Months and days between dates

    What is the formula to find the months and days between dates

    Tricky... The first problem is the intended result. Months have a varying number of days in them, days and weeks have set values. For example the difference between 1st July and 1st September is 2 months but this does not give an accurate count of the number of days (61).
    It would be better to calculate the number of days difference and forget the months.
    You would need a lookup table showing a numeric value for each date that would show each date with a day value from a starting point. If your earliest date is 01/01/2000 then that would be day zero. Then using the lookup table calculate the day value for your beginning and end dates. Subtract one from the other to get the number of days.
    If all your dates are from this year:
    You can create your own Cell Format (call it day of the year) Select the Type: Date & Time
    drag the icon for Day of Year into the box and delete the others.
    Convert your dates to this new Format, subtract one value from the other to get the number of days difference.

  • Counter KF with 1 & 0 and difference between data type NUMBER (DEC) and INTEGER (INT4)

    Hi,
    I need to create a counter kf which should populate 1 and 0 to this counter field. Please let me know is there any difference between data type
    NUMBER (DEC) and INTEGER (INT4).
    Please suggest.
    Thanks & Regards,
    Pavan kumar

    Hi Pavan,
    The basic difference between Number(DEC) and INT4 is its internal storage in system.
    For Number (DEC) - Value internally stored as packed number with 3 decimal places whereas INT 4 as 4 byte integer without decimal places.
    For counter KF, you can go for INT 4.
    Hope this helps.
    Thanks

  • FM to get previous fiscal month/year and calendar month/year for a date.

    Hi All,
    I am having a requirement to extract some data based on either the previous fiscal month/year or the previous calendar month/year. There is no company code input to find the fiscal/calendar month/year.
    At selection screen, user can select either fiscal or calendar selection.
    Based on the selection, the data will be extracted.
    For the system date, we need to calculate previous fiscal month/year or previous calendar month/year and populate the calculated data back to the selection-screen.
    Can you one of you please suggest an FM to find previous fiscal month/year and previous calendar month/year.
    Thanks in Advance,
    Regards
    Gowthami

    Hi Gowthami,
    You can use following function module to calculate previous / next day or month or year.
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    =
            sign      = '-'
            years     =
          importing
            calc_date = .
    Here, you can give '-' to sign, if you want previous day / month / year.
    Here, you can give '+' to sign, if you want next day / month / year.
    And depending upon your requirement, you can pass suitable value to days / month / year.
    e.g. To calcualte last month,
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    = 1
            sign      = '-'
            years     =
          importing
            calc_date = wv_prev_month.
    so it will give '23-01-2008' . Then convert it in the required format as per your requirement using string function concatenate.
    Hope this help you.
    Regards,
    Anil

  • Table where weekly and daily sales data is stored

    Can any one please tell me in which all tables i can get weekly and daily sales as i get in S001 which is period wise.

    S001 Table itself is based on date which you can segerate on week and further daily and may be month. This is communication struture table ,. For futther details look of s*** table if you dont fullfill your requirement
    reward points if useful
    rajesh

  • Weekly and daily sales data Table.

    Can anyone tell me the tables where sales data is stored on weekly and daily basis.
    its urgent please.........

    Hi
    Date wise all Sales orders data is stored in <b>VBAK , VBAP and VBEP</b> tables
    So based on date you can group the data into weeks and Months and can display
    VBAK-AEDAT take this date and do as per the requirement
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Why is the signal at my home so much weaker than when I moved here in February 2013?  I only get one or two bars and very poor data service if any at all.

    Why is the signal at my home so much weaker than it was when I moved here in February 2013?  I get only one or two bars and very poor data service if any at all.  Calling to ask the question results in a vortex of questions that have little to do with the problem and no  resolution or answer.

    I have a Droid Ultra phone.  The signal reduction seems to only be in the general area of my home.  If I go downtown, the signal improves to what it once was at home.  Everything at my home is as it was when the signal was good, including cable TV service.  There has been no new construction in the area that I know of.
    Thanks for trying to resolve the issue.  Just this morning while trying to view web pages, I found that I could not load any.
    Ron

  • Getting a problem in mounting and unmounting the data in NI-9802

    hii,
         i am using 9802 memory module, using cRIO 9081. I want t o use both scan and FPGA mode at the same time. I have compiled a  NI-9802 method FPGA vi,  and then i have simulated the NI-9802 RT access host vi , and getting a error 65010. So anyone can help me to sort out this problem.
    I am also getting a problem, that how to read and write the data in NI-9802. 

    You have to escape the apostrophe. Use this code to format Strings.
      private String formatStringForSQL(String param){
            StringBuffer strBuffer = new StringBuffer();
            if (param == null) {
                return param;
            strBuffer.append("'");
            for (int i = 0; i < param.length(); i++) {
                  if (param.charAt(i)== '\'') {
                     strBuffer.append("\'");
                  } else {
                      strBuffer.append(param.charAt(i));
            strBuffer.append("'");
            return strBuffer.toString();
      }

  • Display all dates between date range (Time Dimension left outer join Fact)

    All,
    I have done some searching around this issue but within all the posts regarding date variables, date prompts and date filtering I haven't seen one exactly answering my issue (maybe they are and I just dont have my head around it correctly yet).
    My report requirement is to allow a user to select a start day and an end day. The report should show all activity between those two days - AND display 0/null on days where there is no activity. That second part is where I am getting hung up.
    The tables in question are:
    TimeDim
    EventFact
    CustomerDim
    My BMM is setup as follows:
    TimeDim left outer join EventFact
    CustomerDim inner join EventFact
    If I run a report selecting DAY from TimeDim and a measure1 from EventFact with day range 1/1/2010 - 12/31/2010 .. I get a record for every day and it looks perfect because of the left outer join between TimeDim and CustomerDim.
    But .. if I add in a field from CustomerDim, select TimeDim.DAY, CustomerDim.CUSTNAME, EventFact.MEASURE1, OBIEE only returns records for the days that have EventFact records.
    This is due to the fact that the TimeDim is still outer joined into EventFact but adding in CustomerDim makes OBIEE setup an inner join between those tables which then causes only data to be returned where EventFact data exists.
    There is a way around this in this simple case and that is to define the relationship between CustomerDim and EventFact as an outer join as well. This will give the desired effect (but an outer join between these two tables is not the true relationship) and as I add additional dimensions and add additional logical sources to a single dimension in the BMM it gets complicated and messy.
    Ive also messed with setting the driving table in the relationship, etc.. but it has not given the desired effect.
    Has anyone ever encountered the need to force display all dates within a specfied range with a fact table that may not have an entry for every date?
    Thanks in advance.
    K
    Edited by: user_K on Apr 27, 2010 11:32 AM

    It worked!!!* Even my time drill downs and date based filtering still work!
    That is awesome. Never would have thought of that intuitively.
    Now, just need a little help understanding how it works. When I run my report and check the logs I can see that two queries are issued:
    Query 1: Joins the fact table to all the associated dimensions. I even changed all the relationships to inner joins (which is what they truly are). And calculates the original measure. If I copy and paste this query into sql developer it runs fine but only returns those rows that joined to the time dimension - which is what was happening before. It is correct but I wanted a record for every time dimension record.
    Query 2: Looks like the following:
    select sum(0)
    from timedim
    where date between <dateprompt1> and <dateprompt2>
    group by month *<--* this is the time dimension level specified in Query 1, so it knows to aggregate to the month level as was done in query 1
    Final Question: So what is OBIEE doing ultimately, does it issue these two requests and then perform a full outer join or something to bring them together? I couldn't see anywhere in the log a complete query that I could just run to see a similar result that I was getting in Answers.
    Thanks for all the help .. Id give more points if I could.
    K

  • Data between Date Range with Business Days only

    Hi All,
    We have a requirement that we need to retrieve data between a data range, providing From date and To date as input.
    We also have the option to Include Business Days Only through a check box which will be passed to CR 2008 through a report frame work.
    Can some one help me how to display the report data within the Date Range entered and that includes only Business Days.
    Thanks in advance for the help.
    Regards,
    Naresh.

    try this formula. Lets if your date range parameter is {?date} then try this formula
    @startdate:
    if datepart('w',minimum({?date}))=7 then
    minimum({?date})+2
    else if datepart('w',minimum({?date}))=1 then
    minimum({?date})+1
    else
    minimum({?date})
    @enddate
    if datepart('w',maximum({?date}))=7 then
    maximum({?date})+2
    else if datepart('w',maximum({?date}))=1 then
    maximum({?date})+1
    else
    maximum({?date})
    regards,
    Raghavendra

  • Generating Dates Between Date Range

    Hi,
    I have a table with test_id, a_id, start_date, end_date like the below.
    test_id a_id start_date end_Date
    861 2123 05-Dec-2009 10-Dec-2009
    861 2124 06-Dec-2009 09-Dec-2009
    864 2123 08-Dec-2009 10-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009
    I need to generate dates between the start_date and end_date like the below. Kindly help.
    test_id a_id start_date end_Date tdate
    861 2123 05-Dec-2009 10-Dec-2009 05-Dec-2009
    861 2123 05-Dec-2009 10-Dec-2009 06-Dec-2009
    861 2123 05-Dec-2009 10-Dec-2009 07-Dec-2009
    861 2123 05-Dec-2009 10-Dec-2009 08-Dec-2009
    861 2123 05-Dec-2009 10-Dec-2009 09-Dec-2009
    861 2123 05-Dec-2009 10-Dec-2009 10-Dec-2009
    861 2124 06-Dec-2009 09-Dec-2009 06-Dec-2009
    861 2124 06-Dec-2009 09-Dec-2009 07-Dec-2009
    861 2124 06-Dec-2009 09-Dec-2009 08-Dec-2009
    861 2124 06-Dec-2009 09-Dec-2009 09-Dec-2009
    864 2123 08-Dec-2009 10-Dec-2009 08-Dec-2009
    864 2123 08-Dec-2009 10-Dec-2009 09-Dec-2009
    864 2123 08-Dec-2009 10-Dec-2009 10-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009 07-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009 08-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009 09-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009 10-Dec-2009
    864 2124 07-Dec-2009 11-Dec-2009 11-Dec-2009
    Please reply at the earliest. Its very urgent. Thanks in advance.
    Regards,
    Gayathri Devi

    with t
    as
    select 861 test_id, 2123 a_id, to_date('05-Dec-2009','dd-mon-yyyy') start_date, to_date('10-Dec-2009','dd-mon-yyyy') end_date from dual union all
    select 861, 2124, to_date('06-Dec-2009','dd-mon-yyyy'), to_date('09-Dec-2009','dd-mon-yyyy') from dual union all
    select 864, 2123, to_date('08-Dec-2009','dd-mon-yyyy'), to_date('10-Dec-2009','dd-mon-yyyy') from dual union all
    select 864, 2124, to_date('07-Dec-2009','dd-mon-yyyy'), to_date('11-Dec-2009','dd-mon-yyyy') from dual
    select test_id, a_id, start_date, end_date, start_date+no-1 dt
      from t
      cross join
    select level no
      from dual
    connect by level <= (select max(end_date-start_date+1) from t)
    where case when start_date+no-1 > end_date then null else start_date+no-1 end is not null
    order by 1,2,5

  • How do I get rid of audio pops and clicks between clips in Final Cut Pro X?

    Is there a layman, non-professional way to do this? These are just video files... i don't know anything about formats of different files and all that, but i read in other posts that the files should be "uncompressed 48k something something", but i dont even know how to convert the audio(From video) that's already on my timeline to this format

    Your clicks probably are related to the fact that you are using the whole clip, leaving no "handles". Handles are extra portions of a clip, before and after the portion you use in your timeline.
    The clicks are probably caused by the camera. You are using whole clips (that is why you get the warning when trying Cmd-T, "there is no extra media..."), so you are starting and ending right where the camera did.
    If possible, trim a little bit at the end and start of each clip. Select just the edge of the clip (not the whole clip) and drag a little bit to shorten it. Just a few frames might be enough.
    For the future, you should remember to let the camera capture a little more than you will actually use - so that you can have those "handles". See the picture.

Maybe you are looking for

  • My skpe to go number is not connecting

    My skype to go number all of a sudden stopped connecting whereas it used to. Need help!

  • Left shift key is stuck down

    My daughters MacBook left shift key is stuckndown.  The computer is constantly on "safe boot". What's a mom to do?

  • How can I use a song like ringtone in IPhone5?

    How can I use a song like ringtone in IPhone5?

  • Survey In Win client

    Does anybody know how to make survey work in winclient using survey suite.  I want to conduct a survey after an activity. thanks eleanor

  • I've lost my itunes library!

    Hi there I am in the process of transferring files from PC to laptop - in a big clear out, I deleted (for good) my music file. I didnt realise my itunes libary was lcoated within this and now my entire itunes library has gone! All my tracks are still